how to save a catalog item value into a table form field

NewBiee
Tera Contributor

I have a requirement where I need to get values like description, category from my catalog item and save it in request (sc_request) form.

I tried writing a business rule for description field but I'm unable to pass values to the business rule from a catalog item.

Can anyone help me pass both description and category values.

screenshots:

find_real_file.png

 

find_real_file.png

find_real_file.png

Thank You.

8 REPLIES 8

Hope the Business Rule is on RITM table & not REQ

Try below & confirm the messages you get

 

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

    var reqis = new GlideRecord('sc_request');
    reqis.addQuery('sys_id', current.request);
    reqis.query();
    if (reqis.next()) {
        gs.addInfoMessage('Ritm is ' + current.number);
        gs.addInfoMessage('Req is ' + reqis.number);
        gs.addInfoMessage('Variable desc ' + current.variables.description);
        gs.addInfoMessage('Variable cate ' + current.variables.category);
        reqis.description = current.variables.description; //replace description1 with correct description variable name
        reqis.short_description = current.variables.category; //replace category with correct category variable name;
        reqis.update();
    }

})(current, previous);

these are the new screenshots

find_real_file.png

 

find_real_file.png

find_real_file.png

find_real_file.png

 

Not sure what is wrong with it.

Aman Kumar S
Kilo Patron

Hey,

Create an After Insert BR on Requested Item table.

Try below code:

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

    var requestGR = new GlideRecord('sc_request');
    requestGR.addQuery('sys_id', current.getValue("request"));
    requestGR.query();
    if (requestGR.next()) {
        requestGR.setValue("description", current.cat_item.description); 
        requestGR.setvalue("short_description", current.cat_item.short_description) ;
        requestGR.update();
    }

})(current, previous);

Now raise a new request and test

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Namrata Ghorpad
Mega Sage
Mega Sage

Hello NewBiee,

Please refer the below code. It's working correct for me. Select the after insert/update business rule on sc_req_item table.

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

// Add your code here
var req=current.request;
gs.addInfoMessage("Request is "+req);
var grreq=new GlideRecord('sc_request');
grreq.addQuery('sys_id',req);
grreq.query();
if(grreq.next())
{
grreq.description=current.variables.enter_description;
grreq.short_description=current.variables.enter_short_description;
grreq.update();
}

})(current, previous);

 

Please mark my answer as correct/helpful if it helps you.

Thanks,

Namrata