public void TestGetObjectTextSetValue() { TextValue textValue1 = new TextValue(); TextValue textValue2 = new TextValue(); textValue1.value = "value1"; textValue2.value = "value2"; SetValue setValue = new SetValue(); setValue.values = new Value[] {textValue1, textValue2}; List<object> value = PqlUtilities.GetValue(setValue) as List<object>; Assert.AreEqual(2, value.Count); Assert.True(value.Contains("value1")); Assert.True(value.Contains("value2")); }
/// <summary> /// Adds a new string value to the list of query parameters. /// </summary> /// <param name="key">The parameter name.</param> /// <param name="value">The parameter value.</param> /// <returns>The statement builder, for chaining method calls.</returns> public StatementBuilder AddValue(string key, string value) { TextValue queryValue = new TextValue(); queryValue.value = value; return AddValue(key, queryValue); }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the CustomFieldService. CustomFieldService customFieldService = (CustomFieldService) user.GetService( DfpService.v201505.CustomFieldService); // Get the LineItemService. LineItemService lineItemService = (LineItemService) user.GetService( DfpService.v201505.LineItemService); // Set the IDs of the custom fields, custom field option, and line item. long customFieldId = long.Parse(_T("INSERT_STRING_CUSTOM_FIELD_ID_HERE")); long customFieldOptionId = long.Parse(_T("INSERT_CUSTOM_FIELD_OPTION_ID_HERE")); long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); try { // Get the drop-down custom field id. long dropDownCustomFieldId = customFieldService.getCustomFieldOption(customFieldOptionId).customFieldId; StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :id") .OrderBy("id ASC") .Limit(1) .AddValue("id", lineItemId); // Get the line item. LineItemPage lineItemPage = lineItemService.getLineItemsByStatement( statementBuilder.ToStatement()); LineItem lineItem = lineItemPage.results[0]; // Create custom field values. List<BaseCustomFieldValue> customFieldValues = new List<BaseCustomFieldValue>(); TextValue textValue = new TextValue(); textValue.value = "Custom field value"; CustomFieldValue customFieldValue = new CustomFieldValue(); customFieldValue.customFieldId = customFieldId; customFieldValue.value = textValue; customFieldValues.Add(customFieldValue); DropDownCustomFieldValue dropDownCustomFieldValue = new DropDownCustomFieldValue(); dropDownCustomFieldValue.customFieldId = dropDownCustomFieldId; dropDownCustomFieldValue.customFieldOptionId = customFieldOptionId; customFieldValues.Add(dropDownCustomFieldValue); // Only add existing custom field values for different custom fields than // the ones you are setting. if (lineItem.customFieldValues != null) { foreach (BaseCustomFieldValue oldCustomFieldValue in lineItem.customFieldValues) { if (!(oldCustomFieldValue.customFieldId == customFieldId) && !(oldCustomFieldValue.customFieldId == dropDownCustomFieldId)) { customFieldValues.Add(oldCustomFieldValue); } } } lineItem.customFieldValues = customFieldValues.ToArray(); // Update the line item on the server. LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] {lineItem}); if (lineItems != null) { foreach (LineItem updatedLineItem in lineItems) { List<String> customFieldValueStrings = new List<String>(); foreach (BaseCustomFieldValue baseCustomFieldValue in lineItem.customFieldValues) { if (baseCustomFieldValue is CustomFieldValue && ((CustomFieldValue) baseCustomFieldValue).value is TextValue) { customFieldValueStrings.Add("{ID: '" + baseCustomFieldValue.customFieldId + "', value: '" + ((TextValue) ((CustomFieldValue) baseCustomFieldValue).value).value + "'}"); } else if (baseCustomFieldValue is DropDownCustomFieldValue) { customFieldValueStrings.Add("{ID: '" + baseCustomFieldValue.customFieldId + "', custom field option ID: '" + ((DropDownCustomFieldValue) baseCustomFieldValue).customFieldOptionId + "'}"); } } Console.WriteLine("A line item with ID \"{0}\" set with custom field values \"{1}\".", updatedLineItem.id, string.Join(", ", customFieldValueStrings.ToArray())); } } else { Console.WriteLine("No line items were updated."); } } catch (Exception e) { Console.WriteLine("Failed to update line items. Exception says \"{0}\"", e.Message); } }
public void TestGetObjectTextValue() { TextValue textValue = new TextValue(); textValue.value = "value1"; Assert.AreEqual("value1", PqlUtilities.GetValue(textValue)); }
public void TestGetTextValueCommaTextSetValue() { TextValue textValue1 = new TextValue(); TextValue textValue2 = new TextValue(); textValue1.value = "value1"; textValue2.value = "comma \",\" separated"; SetValue setValue = new SetValue(); setValue.values = new Value[] { textValue1, textValue2 }; Row row = new Row(); row.values = new Value[] { setValue }; string[] stringValues = PqlUtilities.GetRowStringValues(row); Assert.AreEqual(1, stringValues.Length); Assert.AreEqual("value1,\"comma \"\",\"\" separated\"", stringValues[0]); }
public void TestGetObjectNestedSetValue() { SetValue setValue = new SetValue(); SetValue innerSetValue = new SetValue(); TextValue textValue = new TextValue(); textValue.value = "value1"; innerSetValue.values = new Value[] { textValue }; setValue.values = new Value[] {innerSetValue}; PqlUtilities.GetValue(setValue); }
public void TestGetObjectMixedSetValue() { TextValue textValue = new TextValue(); DateValue dateValue = new DateValue(); textValue.value = "value1"; Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; dateValue.value = date; SetValue setValue = new SetValue(); setValue.values = new Value[] { textValue, dateValue }; PqlUtilities.GetValue(setValue); }