copy other module custom fields to SO custom fields  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Re: copy other module custom fields to SO custom fields

Postby Mike.Sheen » Fri Mar 06, 2015 3:10 pm

Hi Danny,

You can get to the inventory business logic via the custom field value you already have:

Code: Select all
Dim inventory As JiwaInventory.Inventory = DirectCast(customFieldValue.CustomField.CustomFieldCollection.BusinessLogic, JiwaInventory.Inventory)


Your snippet with the above incorporated into it would be something like this:

Code: Select all
Sub ChangedCustomField(Sender As Object, e As System.EventArgs)
    Dim customFieldValue As JiwaApplication.CustomFields.CustomFieldValue = DirectCast(sender, JiwaApplication.CustomFields.CustomFieldValue)
   Dim inventory As JiwaInventory.Inventory = DirectCast(customFieldValue.CustomField.CustomFieldCollection.BusinessLogic, JiwaInventory.Inventory)
   
   If customFieldValue.CustomField.PluginCustomField.Name = "CustomField1" Then
      If CustomFieldValue.Contents = 0 Then
         inventory.CustomFieldValues.ItemFromSettingName("CustomField2").Contents = ""
      End If
      If CustomFieldValue.Contents = 1 Then
         inventory.CustomFieldValues.ItemFromSettingName("CustomField2").Contents = "Some text"
      End If
   End If   
End Sub


Mike
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: copy other module custom fields to SO custom fields

Postby DannyC » Fri Mar 06, 2015 4:57 pm

Thanks Mike. When I have the suggested line
Code: Select all
Dim inventory As JiwaInventory.Inventory = DirectCast(customFieldValue.CustomField.CustomFieldCollection.BusinessLogic, JiwaInventory.Inventory)

I can't read the custom field name and value.

If I comment out that line, then I can.
Is there something about that line that is causing the read of the name & value (e.g this line)
Code: Select all
Msgbox(String.Format("Custom Field '{0}' has a value of '{1}'", customFieldValue.CustomField.PluginCustomField.Name, customFieldValue.Contents)

to fail with the error "Object reference not set to an instance of an object" ?
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: copy other module custom fields to SO custom fields

Postby Mike.Sheen » Sat Mar 07, 2015 9:57 am

Ahhh - my bad - I should have used:

Code: Select all
Dim inventory As JiwaInventory.Inventory = DirectCast(customFieldValue.CustomFieldValueCollection.CustomFieldCollection.BusinessLogic, JiwaInventory.Inventory)


Getting to the business logic the way I originally suggested would fail when the custom field is being edited for the first time because customFieldValue.CustomField.CustomFieldCollection is null at that point.

Attached is a plugin which does what you want (Note the attached plugin adds two custom fields to inventory "CustomField1" and "CustomField2" which will very likely clash with your existing one - which highlights the reason to use the ItemFromSettingName method which includes the plugin name as well as the custom field name to disambiguate which custom field you want).

Plugin Test.xml
Sample plugin
(33.01 KiB) Downloaded 429 times


Mike
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Previous

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests