Page 1 of 1

ReadCustomFieldValue not working

PostPosted: Tue Jan 24, 2023 12:43 pm
by SBarnes
I have a custom field on inventory as a checkbox called IProduct and is called in code like this

Code: Select all
string cField = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection.ReadCustomFieldValue(salesOrder.Manager, "IN_CustomSettingValues", "InventoryID", inventory.InventoryID, "IProduct");


cField is ending up as null.

But if Irun sql profiler and take the following and run it in SSMS it returns a value as True which is what I am expecting it to do

Code: Select all
exec sp_executesql N'SELECT Contents FROM IN_CustomSettingValues WHERE InventoryID = @ID AND SettingID = (SELECT SettingID FROM IN_CustomSetting WHERE SettingName = @SettingName)',N'@ID char(20),@SettingName varchar(8)',@ID='ECBF488B31CE4E80B867',@SettingName='IProduct'


Any ideas as to what would cause the function call to return null?

Re: ReadCustomFieldValue not working

PostPosted: Tue Jan 24, 2023 1:47 pm
by Mike.Sheen
Is the plugin in which this custom field is defined enabled?

Re: ReadCustomFieldValue not working

PostPosted: Tue Jan 24, 2023 2:01 pm
by SBarnes
Its in the same plugin but here is the weird thing in another plugin async or sync like in the below works and change products and the code that wasn't working does work.


Code: Select all
public class ApplicationManagerPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaApplicationManagerPlugin
{

    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
//      string cField = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection.ReadCustomFieldValue(Plugin.Manager, "IN_CustomSettingValues", "InventoryID", "ECBF488B31CE4E80B867", "IProduct");
//      if(cField != null)
//      {
//         System.Windows.Forms.MessageBox.Show(cField);
//      }
      
      
        string result = "";
          var taskw = Task.Run(async () => result = await Test(Plugin));
      
        taskw.Wait();
      if(result != null)
      {
         System.Windows.Forms.MessageBox.Show(result);
      }
      
    }
   
   
   public async Task<string> Test(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
   {
      string cField = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection.ReadCustomFieldValue(Plugin.Manager, "IN_CustomSettingValues", "InventoryID", "ECBF488B31CE4E80B867", "IProduct");
      return cField;
   }
}

Re: ReadCustomFieldValue not working  Topic is solved

PostPosted: Tue Jan 24, 2023 2:14 pm
by Mike.Sheen
Provide a sample plugin which exhibits the problem and we should be able to work it out fairly quickly.

Re: ReadCustomFieldValue not working

PostPosted: Tue Jan 24, 2023 2:19 pm
by Mike.Sheen
SBarnes wrote:change products and the code that wasn't working does work


I bet your "True" in the contents has a leading or trailing whitespace - that would explain why:
1. Method ReadCustomFieldValue isn't converting to BIT and returning null
2. Running the query and looking at the results it "looks" like it's returning "True"
3. Using a different part and it all works fine (the contents isn't messed up).

Re: ReadCustomFieldValue not working

PostPosted: Tue Jan 24, 2023 3:23 pm
by SBarnes
ReadCustomFieldValue returns a string but in the end I've gone around the problem and coded it differently.

Re: ReadCustomFieldValue not working

PostPosted: Tue Jan 24, 2023 3:26 pm
by Mike.Sheen
SBarnes wrote:ReadCustomFieldValue returns a string but in the end I've gone around the problem and coded it differently.


Ok - so was this incorrect:
SBarnes wrote:cField is ending up as null


I've come across this very issue before where someone has written a SQL script to bulk update values and set the Contents to be not quite what we expect, and that's enough to make what looks like a true value in the Contents actually show up as unticked on the screen.

Re: ReadCustomFieldValue not working

PostPosted: Tue Jan 24, 2023 3:30 pm
by SBarnes
Nope cField was null confirmed in the debugger and next part was



Code: Select all
                if (cField == null)
                {
                    cField = "";
                }

                if (cField.ToUpper() != "TRUE")
                {
                    salesOrder.OrderType = SalesOrder.SalesOrderOrderTypes.e_SalesOrderOrderTypeReserveOrder;
                }



And I got a reserved order.

I would have debugged it but I don't want to move 137GB db locally.