Populate Short Description with Form Variable Values in requested item record

Sahar_Kaizer
Tera Contributor

Hi,

 

I've set up a catalog item named 'change site' that includes fields like 'version,' 'unit,' and 'system.'

Additionally, I've created a business rule that, upon saving the record, should populate the 'short_description' field of the requested item with a string composed of the chosen values in the mentioned fields - 'chosen version / chosen unit / chosen system/ request name', but it doesnt work.

this is the business rule:

Sahar_Kaizer_0-1703688843878.png

 

However, I'm encountering some challenges with this setup. Could someone please provide guidance or suggestions?

 

Thanks,

Sahar

15 REPLIES 15

Hi @Sahar_Kaizer ,

You can try this to see if it is returning the correct values :

var gr = new GlideRecord('sc_item_option_mtom');

gr.addQuery('request_item',<RITM sysid>); // this will give you list of all the variables

gr.query();

while(gr.next())
{

var vargr = new GlideRecord('sc_item_option');

vargr.addQuery('sc_item_option', <sysid of variable value you need>);

vargr.query();

while(vargr.next())
{
gs.info('Value of variable is ' + vargr.value);
}

}

SunilKumar_P
Giga Sage

Hi @Sahar_Kaizer, You need to use current.variables.<yourVariableName> in BR (sc_req_item) to retrieve the variable value. Can you try the below script?

 

(function executeRule(current, previous /*null when async*/) {

    var nonEmptyValues = [];
    if (current.variables.version) {
        nonEmptyValues.push(current.variables.version);
    }
    if (current.variables.unit) {
        nonEmptyValues.push(current.variables.unit);
    }
    if (current.variables.system) {
        nonEmptyValues.push(current.variables.system);
    }

    current.short_description = nonEmptyValues.join('/');

})(current, previous);
 
Regards,
Sunil
 

Jyoti Jadhav9
Tera Guru

Hi @Sahar_Kaizer , Please try the below code:

 

Table - Requested Item(sc_req_item)
When to Run - Before Insert

condition: item is change site
Script -

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
var version = current.variables.version;
var unit = current.variables.unit;
var system = current.variables.system;
/*current.short_description = 'Chosen Version:- ' + version + '\n' +
'Chosen Unit:- ' + unit + '\n' +
'Chosen system:- ' + system;*/
current.short_description = version + '/' + unit + '/' + system;
 
})(current, previous);
 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

 

Thanks & Regards

Jyoti Jadhav

ashishdevsingh
Tera Expert

hi @Sahar_Kaizer ,

I don't think that you need to write the complex logic . I have tried in PDI and below code works for me:

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var nonEmptyValues = [];
    if (!gs.nil(current.variables.var_version)) {
        nonEmptyValues.push(current.variables.var_version);
    }
    if (!gs.nil(current.variables.var_system)) {
        nonEmptyValues.push(current.variables.var_system);
    }
    if (!gs.nil(current.variables.var_unit)) {
        nonEmptyValues.push(current.variables.var_unit);
    }

    var shortDesc = nonEmptyValues.join("/");
    current.short_description = shortDesc;

})(current, previous);
 
- I have tried with Before business rule. 
attaching the screenshot. 
ashishdevsingh_0-1704656971284.png

 

 

ashishdevsingh
Tera Expert

hi @Sahar_Kaizer 

- I have written below code in PDI and it works for me. 

BR Type: before insert. Condition you may defined and restrict to run on particular catalog item. 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var nonEmptyValues = [];
    if (!gs.nil(current.variables.var_version)) {
        nonEmptyValues.push(current.variables.var_version);
    }
    if (!gs.nil(current.variables.var_system)) {
        nonEmptyValues.push(current.variables.var_system);
    }
    if (!gs.nil(current.variables.var_unit)) {
        nonEmptyValues.push(current.variables.var_unit);
    }

    var shortDesc = nonEmptyValues.join("/");
    current.short_description = shortDesc;

})(current, previous);
- I have attached the screenshot for your reference. 
PS: you can do it via using flow designer as well if you are trying to perform more step like task creation etc. 
Please mark if it helps.