variable editor on request item

ma kaiyue
Giga Guru

catalog item when hitting submit, I want to put a value in the variable editor in the generated request item. So I want to know how the variable editor in the request item is used in the script and if what I want to do is possible? Or do you have any better suggestion for me?

Thanks in advance!

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

Variable editor will basically show the field values entered by the user while submitting the catalog.

If you want to set another variable while submission, create a variable in your catalog item and then set the value of that variable using an onSubmit Client script in you catalog item.


Please mark this response as correct or helpful if it assisted you with your question.

Yashsvi
Kilo Sage

Hi @ma kaiyue,

1-Catalog Client Script: This script runs on the client side (browser) and can be used to perform actions when a user interacts with the catalog item form. It can be used to set or modify variables before submission.

function onSubmit() {
// Assuming you have a variable named 'editor' in the catalog item
g_form.setValue('editor', 'desired_value');
return true;
}


2-Catalog Business Rule: This script runs on the server side and can be used to modify the request item after submission. It can set or change variables in the request item based on certain conditions or logic.

Table: Select "sc_req_item"
When: Select "after"

(function executeRule(current, previous /*null when async*/) {
    // Assuming you have a variable named 'editor' in the request item
    var gr = new GlideRecord('sc_item_option_mtom');
    gr.addQuery('request_item', current.sys_id);
    gr.addQuery('sc_item_option.item_option_new.name', 'editor');
    gr.query();
    if (gr.next()) {
        gr.sc_item_option.value = 'desired_value';
        gr.update();
    }
})(current, previous);

 

Thank you, please make helpful if you accept the solution.