Can I dynamically set a PXDataFieldAssign parameter of a PXDataFieldParam object? - acumatica

I have code that sets the PXDataFieldAssign value as follows:
pf = new PXDataFieldAssign<xTACProjectTask.dueDate>(someValue);
I also have a table, holding the DAC field names, such as "xTACProjectTask.dueDate". This table also has a checkbox field to determine whether to use this DAC field as a parameter.
Is there a way to not have the DAC fieldname hard-coded, and instead (maybe using a 'typeof' call?) use the results of the table query to set that field name - like the following?
pf = new PXDataFieldAssign<typeof("xTACProjectTask.dueDate")>(someValue);
or, using my query result:
pf = new PXDataFieldAssign<typeof(query.value)>(someValue);
with query.value being the value in the table holding the DAC field name?

You can create it using Type.GetType and Activator.CreateInstance. Please see the example below:
string typeName = "PX.Objects.IN.InventoryItem+descr,PX.Objects";
Type typeArgument = Type.GetType(typeName);
Type genericClass = typeof(PXDataFieldAssign<>);
Type constructedClass = genericClass.MakeGenericType(typeArgument);
object created = Activator.CreateInstance(constructedClass,new object[] { "Test Description" });
You will get the below wrapped into object in the created

Related

How do I call NetSuite SuiteTalk inventoryitem add using list name for StringCustomFieldRef value instead of internalID?

When adding a new inventoryitem through the API we have a few list based custom fields we need to fill in. I want to be able to use the string value for the field but when I try to the call errors out.
We have a custom list with two values:
InternalId 1 is "LTL"
InternalId 2 is "FedEx"
I have tried sending the value across as a StringCustomFieldRef and when setting the value to the string value of the "LTL" we get an invalid ref error. When setting the value to the internalId of 1 it works.
I also tried using a SelectCustomFieldRef and when setting the value->name to the string value of "LTL" it errors like we did not pass the value at all. When we set value->internalId to 1 it works.
Is it possible to just pass in the string value?
Does not work:
$customField1 = new StringCustomFieldRef();
$customField1 ->value = "LTL";
$customField1 ->scriptId = 'custitem_zu_zu_fulfill_pref';
Works:
$customField1 = new StringCustomFieldRef();
$customField1 ->value = "1";
$customField1 ->scriptId = 'custitem_zu_zu_fulfill_pref';
This is the error response:
<platformCore:statusDetail type="ERROR">
<platformCore:code>INVALID_KEY_OR_REF</platformCore:code>
<platformCore:message>Invalid custitem_zu_zu_fulfill_pref reference key LTL.</platformCore:message>
</platformCore:statusDetail>
No, unfortunately you cannot set a field with the Name value--you will have to use the internalId. If your custom field is list-based, then you should be using SelectCustomFieldRef or MultiSelectCustomFieldRef.
If you wish to use the Name value, you can perform a CustomListSearchBasic to get the Name and internalId of each item, and match that to your chosen Name.

Putting string after a where clause in a soql query in salesforce

I have the filter logic parsed and put as a string in a variable called "where_clause". I have to use this where_clause in a query to fetch data.How can I use a string of this type after the where part of the query?I am working on salesforce with custom objects.
I suggest you check Dynamic SOQL.
In particular
String myTestString = 'TestName';
List<sObject> sobjList = Database.query('SELECT Id FROM MyCustomObject__c WHERE Name = :myTestString');
If you have your Custom Object as MyCustomObject__c
String myTestString = 'TestName';
List<MyCustomObject__c> sobjList = (List<MyCustomObject__c>)Database.query('SELECT Id FROM MyCustomObject__c WHERE Name = :myTestString');

Exporting Business Account attributes with Acumatica API

Our Business Accounts in Acumatica have 13 custom Attributes for our main Business Account Class. I've been able to save values to the Attributes successfully, based on Acumatica's example "Adding Records to the Business Accounts and Opportunities Forms". But I have not been able to figure out how to retrieve the values with an Export.
First, I tried using a format similar to how the field was specified when saving them.
Public Function GetCustomerAttributes(ByVal customerID As String) As String()()
Dim customer As CR303000Content = m_context.CR303000GetSchema()
m_context.CR303000Clear()
Dim idFilter As Filter = New Filter()
idFilter.Field = customer.AccountSummary.BusinessAccount
idFilter.Condition = FilterCondition.Equals
idFilter.Value = customerID
' SIMILAR TO EXAMPLE FOR SAVING
Dim awdField As Field = New Field()
awdField.ObjectName = customer.Attributes.Attribute.ObjectName
awdField.FieldName = "AWD Number"
Dim searchfilters() As Filter = {idFilter}
Dim searchCommands() As Command = {awdField}
Dim searchResult As String()() = m_context.CR303000Export(searchCommands, searchfilters, 0, False, False)
Return searchResult
End Function
I thought this would return one result with the value for our attribute named "AWD Number". Instead, it returned 13 results, one for each attribute, and the value of each one was blank. I changed the FieldName to customer.Attributes.Attribute.FieldName and then it started returning the name of each attribute. So I thought if I added another field for the value, then I might get the name and value in separate results, like this:
Public Function GetCustomerAttributes(ByVal customerID As String) As String()()
Dim customer As CR303000Content = m_context.CR303000GetSchema()
m_context.CR303000Clear()
Dim idFilter As Filter = New Filter()
idFilter.Field = customer.AccountSummary.BusinessAccount
idFilter.Condition = FilterCondition.Equals
idFilter.Value = customerID
Dim awdField As Field = New Field()
awdField.ObjectName = customer.Attributes.Attribute.ObjectName
awdField.FieldName = customer.Attributes.Attribute.FieldName
Dim awdValue As Field = New Field()
awdValue.ObjectName = customer.Attributes.Attribute.ObjectName
awdValue.FieldName = customer.Attributes.Attribute.Value
Dim searchfilters() As Filter = {idFilter}
Dim searchCommands() As Command = {awdField, awdValue}
Dim searchResult As String()() = m_context.CR303000Export(searchCommands, searchfilters, 0, False, False)
Return searchResult
End Function
I did get a 2-item array back for each of the 13 results, but the value in the second field was still blank.
Does anyone know how I can get the values? I don't really care if I have to get them one at a time, but I'd prefer to get them all at once with their names or codes so that I don't have to rely on the indices always staying the same. Below are images of the debugger running on my second example and view in Acumatica. Thanks!
Your first attempt is correct, however you're not using the right object name and field name. The system will dynamically add fields to the primary object (view) of the screen, in this case the object name represented by customer.AccountSummary.BusinessAccount.ObjectName variable (I suggest you use the debugger to see what this value equals too - good learning exercise).
The attribute field name will use the same naming convention as used in How To Retrieve An Attribute Field In StockItems In Acumatica API?. The naming convention is _Attributes. The attribute ID is not the attribute name; I don't see your configuration but I doubt in your case the Attribute ID is "AWD Number". To summarize, the code will look like:
Dim awdField As Field = New Field()
awdField.ObjectName = customer.AccountSummary.BusinessAccount.ObjectName
awdField.FieldName = "AWDNumber_Attributes"
In your example, by putting the Attributes.Attribute.ObjectName object, the system will iterate through all values inside this table, and then return for every row the fields you want. I'm not exactly sure why you're not seeing all the attribute values in this case, but I think you should be fine with the example above.

Netsuite Inventory Item Custom Fields Update

I am trying to figure out how to update a custom field on InventoryItem record in Netsuite. I can update regular fields, but can not seem to update anything
InventoryItem item = new InventoryItem();
WriteResponse response;
List<CustomFieldRef> oCustomFieldRefList = new List<CustomFieldRef>();
item.internalId = "9";
StringCustomFieldRef objStringCustomFieldRef = new StringCustomFieldRef();
objStringCustomFieldRef.internalId = "custitem_main_photo";
objStringCustomFieldRef.value = "http://www.google.com/test.jpg";
oCustomFieldRefList.Add(objStringCustomFieldRef);
item.customFieldList = oCustomFieldRefList.ToArray();
response = _nsService.update(item);
The status returned by the update call is Success. It just doesn't update the custom field. I've tried different fields and types, but nothing seems to save.
The internalId of the custom field is the numeric id, not the string id. Not sure why the documentation all shows the string id value, but using the number fixed the problem for me.
Instead of assigning internal Id, assign scriptId.
Turn this
objStringCustomFieldRef.internalId = "custitem_main_photo";
to this:
objStringCustomFieldRef.scriptId = "custitem_main_photo";

Dynamic Object C# 4.0 , Creating columns at runtime from Pre-defined values

I have used dynamic object but here is a situation where the column names comes from a pre-defined string arrays.How can i create objects at runtime with these pre-defined set of column values?.
The reason why i wanted to do this way is to create a custom class and add custom validation attributes in it so that i can use reflection at runtime to populate values to these dynamic objects mapped to my custom class and validate the values using a single function.
dynamic x = new MyCustomClass();
x.Name = "Jones"; // The Field or Column name "Name" comes from a array of strings.
Validator.Validate(x); //Here i use reflection to iterate through the custom attributes on MyCustomClass and validate them based on conditions.
Is it possible to do something like this x."Name" = "Jones"; :-)
I would suggest perhaps adding an indexer property to your MyCustomClass?
public string this[string binder] {
get {
string result;
return (this.TryGetMember(binder, out result)) ? result : string.Empty
}
set {
this.TrySetMember(binder, value);
}
}
x["Name"] = "Jones";

Resources