Question

System Settings Query Issue

Hello, I am attempting to get an integer I set in the system settings, but when I try to get the value it reads as undefined.

The code is here

        this.Terrasoft.SysSettings.querySysSettingsItem("UsrMADP",
                                function(createInvoiceFromOrderProcessValue) {
                                    var sysProcessId;
                                    if (createInvoiceFromOrderProcessValue &&
                                        createInvoiceFromOrderProcessValue.value) {
                                        sysProcessId = createInvoiceFromOrderProcessValue.value;
                                        cardScope.set("MaxSetting", sysProcessId);
                                            
                                    }
                                
                                }, this);
                                    alert(cardScope.get("MaxSetting").value);

I set the value of the setting by setting it's default value, is this not the way it needs to be done?

Like

6 comments

If it is showing as undefined in the alert, that is because your alert is outside of the querySysSettingsItem callback function. This query is done asynchronously, so the alert shows before the callback function has completed. Also, I assume cardScope is set to reference "this" before the code you've provided? (if that is the case, "this" scope is properly set inside the callback already)

Ryan Farley,

Still getting it as undefined when within the function like so with a different integer I set up.

this.Terrasoft.SysSettings.querySysSettingsItem("hello",
                                function(createInvoiceFromOrderProcessValue) {
                                    var sysProcessId;
                                    if (createInvoiceFromOrderProcessValue &&
                                        createInvoiceFromOrderProcessValue.value) {
                                        sysProcessId = createInvoiceFromOrderProcessValue.value;
                                    }
                                    alert(sysProcessId);

                                   alert(createInvoiceFromOrderProcessValue.value);
                                
                                }, this);

Is there a specific keyword for getting the default value?

nickF,

It depends on the type of setting you are accessing. If the Type of the setting is text, what you are passed *is* the default value. For example: 

Terrasoft.SysSettings.querySysSettingsItem("FinishedTaskColor", function(finishedTaskColor) {
    val taskColor = finishedTaskColor;
    // taskColor now contains the default value of #A0A0A0
}, this);

However, if your setting is a complex type, such as aType of Lookup, then you're returned an object (which still does represent the default value) and you'll have a value property with the ID and displayValue with the text. For example:

Terrasoft.SysSettings.querySysSettingsItem("PrimaryCurrency", function(primaryCurrency) {
    var id = primaryCurrency.value;
    var text = primaryCurrency.displayValue; 
}, this);

For your case, if your system setting is a Text type, then just remove the ".value" from it and your createInvoiceFromOrderProcessValue variable will contain the default value.

It worse if I use it as a string. I can just pass it through parseint to compare it to a value.

 

Thanks

nickF,

You don't need to specify the setting as a Text setting. It can be an Integer Type setting, in which case it provides the parameter as an integer. For example: 

// get MaxFileSize setting, which is an Integer Type
 
Terrasoft.SysSettings.querySysSettingsItem("MaxFileSize", function(maxFileSize) {
    var maxSize = maxFileSize; console.log(maxSize);
    // maxSize now contains the default value of 10
    this.console.log("Is maxSize an Integer? " + Number.isInteger(maxSize));
}, this);

 

Dear Nick, 

Also wanted to add to the above mentioned information, that you can receive undefined in case there are no access rights to the system setting for user.

Regards,

Anastasia

Log in or register to comment