Update a plugin System Setting programatically  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Update a plugin System Setting programatically

Postby SBarnes » Tue Jan 12, 2021 8:48 am

If

Code: Select all
manager.Database.ReadSysData(PluginName, "IncludeBackOrders", "0").ToString()


will read a plugins system setting how do I update it through code?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Update a plugin System Setting programatically  Topic is solved

Postby Scott.Pearce » Tue Jan 12, 2021 8:58 am

Code: Select all
manager.Database.SaveSysData(PluginName, "IncludeBackOrders", "0");
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Update a plugin System Setting programatically

Postby SBarnes » Tue Jan 12, 2021 9:01 am

Thanks
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Update a plugin System Setting programatically

Postby SBarnes » Wed Feb 24, 2021 12:24 pm

What about for a datetime do you need to format up a string and if so what format?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Update a plugin System Setting programatically

Postby Mike.Sheen » Wed Feb 24, 2021 3:12 pm

SBarnes wrote:What about for a datetime do you need to format up a string and if so what format?


ISO-8601 format - we actually don't do this ourselves (logged as DEV-8616) but you should store as ISO 8601 format (in .NET use the "s" format specifier). We happily read ISO 8601 format dates and will display them in the format of the system culture, but sadly we write them back currently in the short date format of the system culture.

So, use .ToString("s") - that'll produce a string like "2021-02-24T00:00:00".
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: Update a plugin System Setting programatically

Postby SBarnes » Wed Feb 24, 2021 5:26 pm

How can I convert the string from manager.Database.ReadSysData(PluginName, "ISOUpdate", "0").ToString(); to a datetime the following with a format of MM/dd/yyyy hh:mm:ss tt isn't working which is pretty much the format it is?

Code: Select all
        public static DateTime ToDateTime(this string value, string format = "")
        {
            DateTime outdate = DateTime.Now;
            if (format == "")
            {
                format = SettingsVault.DateTimeFormat;
            }

            if (DateTime.TryParseExact(value, format,
                CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces,
                out outdate))
            {
                return outdate;
            }
            else
            {
               return DateTime.MinValue;
            }
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Update a plugin System Setting programatically

Postby Mike.Sheen » Wed Feb 24, 2021 5:49 pm

ParseExact (which should behave the same in terms of formatting interpretation) worked for me when I provided a format matching what you describe ("MM/dd/yyyy hh:mm:ss tt")

ParseExact.png
ParseExact.png (6.16 KiB) Viewed 243 times


If you can't get that to work, then I'd be wanting the exact format you're using and the exact string value you are attempting to convert.
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: Update a plugin System Setting programatically

Postby SBarnes » Wed Feb 24, 2021 5:52 pm

I found a simpler solution

Code: Select all
DateTime dtTest = (DateTime)manager.Database.ReadSysData(PluginName, "ISOUpdate", "0");
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Update a plugin System Setting programatically

Postby Mike.Sheen » Wed Feb 24, 2021 6:01 pm

SBarnes wrote:I found a simpler solution

Code: Select all
DateTime dtTest = (DateTime)manager.Database.ReadSysData(PluginName, "ISOUpdate", "0");


There might be some problems if you have a machines with different formats reading the same data - so a machine using US date format MM/dd/yyyy will interpret the string "01/07/2021" differently to machine using AU date formats. Which is why I recommend storing in ISO 8601 yyyy-MM-dd format. Doesn't help that we have a shortcoming in our own System settings form which uses the machine culture format - but we're gonna fix that!

Right now, if you do have a mix of clients with different culture / regional formats then you're going to have a bad time.

We sorted this all out with dates for custom fields - we just didn't think to apply the same to system settings of type date.
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: Update a plugin System Setting programatically

Postby SBarnes » Wed Feb 24, 2021 6:09 pm

Just an idea but maybe something similar to the functions on the generic object object collection like SetOrUpdate would be helpful on the custom field??

As for the cast it should be ok as this is on a scheduled plugin where the customers server is also a remote server i.e. all clients and services on the same server.

But given I also need to do a similar thing for another client I may just revert to using text custom fields that way I can control the going in and coming out.
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 4 guests

cron