ReadCustomFieldValue not working  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

ReadCustomFieldValue not working

Postby SBarnes » Tue Jan 24, 2023 12:43 pm

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?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: ReadCustomFieldValue not working

Postby Mike.Sheen » Tue Jan 24, 2023 1:47 pm

Is the plugin in which this custom field is defined enabled?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: ReadCustomFieldValue not working

Postby SBarnes » Tue Jan 24, 2023 2:01 pm

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;
   }
}
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: ReadCustomFieldValue not working  Topic is solved

Postby Mike.Sheen » Tue Jan 24, 2023 2:14 pm

Provide a sample plugin which exhibits the problem and we should be able to work it out fairly quickly.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: ReadCustomFieldValue not working

Postby Mike.Sheen » Tue Jan 24, 2023 2:19 pm

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).
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: ReadCustomFieldValue not working

Postby SBarnes » Tue Jan 24, 2023 3:23 pm

ReadCustomFieldValue returns a string but in the end I've gone around the problem and coded it differently.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: ReadCustomFieldValue not working

Postby Mike.Sheen » Tue Jan 24, 2023 3:26 pm

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.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: ReadCustomFieldValue not working

Postby SBarnes » Tue Jan 24, 2023 3:30 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 34 guests

cron