How to populate Final output in one variable based on two form input values on catalog form

raj99918
Tera Contributor

Hi

 

I have one catalog form having two variables called Input1 and Input2 based on these two values need to populate respective value on FINALOUTPUT variable. If combinations are less numbers I would have go with catalog client script with add and remove methods to populate but I have around 800 combinations to populate this final output What will be easiest solutions for this one ?

 

Thanks

9 REPLIES 9

@raj99918 

2 approaches

1) Custom table

-> create 3 fields, 1 field to hold variable 1 value, 2nd field to hold variable 2 value, 3rd field holds value to be fetched

-> then via GlideAjax, query that table with both the fields and get the 3rd field value and return that

-> use data load via excel file to store those 800 records into custom table

2) Use system property, JSON

-> create a system property of type string and store JSON

then use something like this and pass 2 values via GlideAjax and get value from that JSON by parsing and return that value

JSON will be like this, you need to store 800 array of objects in that in system property, I showed for 2

[{"variableName1":"abel","variableName2":"beth","valueToFetch":"abc"},{"variableName1":"mark","variableName2":"putin","valueToFetch":"def"}]

Sample script

// Sample JSON array
// use gs.getProperty() to get that JSON
var jsonString = '[{"variableName1":"abel","variableName2":"beth","valueToFetch":"abc"},{"variableName1":"mark","variableName2":"putin","valueToFetch":"def"}]';
var jsonArray = JSON.parse(jsonString);

// Input values to match, pass this via GlideAjax
var inputVar1 = 'mark';
var inputVar2 = 'putin';

// Function to get the valueToFetch
function getValueToFetch(arr, var1, var2) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i].variableName1 == var1 && arr[i].variableName2 == var2) {
            return arr[i].valueToFetch;
        }
    }
    return null; // Not found
}

// Usage
var result = getValueToFetch(jsonArray, inputVar1, inputVar2);
gs.info(result); // Output: def

I believe I provided 2 best approaches and you can take it further from here.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@raj99918 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@raj99918 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@raj99918 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@raj99918 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader