Forcing creation of custom value records.  Topic is solved

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

Forcing creation of custom value records.

Postby pricerc » Tue Jul 20, 2021 9:51 am

If you don't add any custom data to, e.g. a sales order or quote, the underlying SQL records are not created, which I think is quite fine.

However, the customer has a 'viewer' web app (inherited from Jiwa 6; should probably convert it to using the API, but that's a different topic), and have asked if the custom values can be populated always, even if they're blank.

Is it sufficient to just 'touch' any custom value in, say, SalesOrder_SaveStart ?

I am going to have a discussion with them about maybe fixing their viewer, but thought I would ask, since there may be a good case for it, and the answer may be interesting to others.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 518
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 21

Re: Forcing creation of custom value records.

Postby SBarnes » Tue Jul 20, 2021 10:27 am

I use the save start on inventory and debtor to check for custom fields that I want to be required against a static class that contains a list of the field names so I can't see why you can't do the same sort of thing and fill in the blanks given under the hood I believe you are really dealing with a Jiwa Collection and Jiwa collection Item so all you really need to do is force the change flags to true and it should save it which putting in some sort of default value like an empty string should do.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Forcing creation of custom value records.  Topic is solved

Postby Mike.Sheen » Tue Jul 20, 2021 11:39 am

Setting the contents to anything will work, but you cannot just set the Insert or ChangeFlag - you need to also set the SettingValueID/RecID to be a newGUID.

This is the property setter of the Contents property of CustomSettingValue (ignore the first part relating to date formatting):

Code: Select all
Set(ByVal Value As String)
   If CustomFieldValueCollection IsNot Nothing AndAlso _CustomField.PluginCustomField.CellType = Plugin.CustomField.CellTypes.Date Then
      If Value Is Nothing OrElse Value.Trim.Length = 0 Then
         _Contents = Value
      Else
         Dim dateValue As DateTime
         If DateTime.TryParse(Value, dateValue) Then
            _Contents = dateValue.ToString("s")
         Else
            Throw New InvalidCastException(String.Format("Value '{0}' cannot be cast to a type of Datetime", Value))
         End If
      End If
   Else
      _Contents = Value
   End If

   If CustomFieldValueCollection IsNot Nothing AndAlso CustomFieldValueCollection.Displaying = False AndAlso (SettingValueID Is Nothing OrElse SettingValueID.Trim.Length = 0) Then
      ' We set the insert flag to be true here, because when we read
      ' in the custom field values, any missing values are still added
      ' to the collection, but with a blank or empty SettingValueID.
      ' If the user doesn't change the setting value, then no setting
      ' value is created, but if they do change it, we need to do an insert.
      m_RecID = CustomFieldValueCollection.Manager.Database.NewGUID  ' m_RecID  is the private field backing the RecID property and for some reason we have another property SettingValueID which also just gets and sets m_RecID
      InsertFlag = True
      ChangeFlag = True
   End If

   NotifyPropertyChanged("Contents")
End Set
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


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests