Clear catalog variables value after the ritm is closed completed

krishna111
Tera Contributor

Hello All,

 

Hope everyone is doing good!!

I have a requirement to clear the catalog attachment variables value in the 'sc_item_option_mtom' table once the RITM is closed completed.

I have 3 mandatory attachment variables for a catalog item after the closure of the request generally the users tend to remove the attachment due to documents confidentiality , after removal the ritm and sctask tabs gets stuck i.e we cannot move to variables, attachments, notes tabs.. to solve this you will need to clear the value of those attachment variables in the sc_item_option_mtom table then it works fine.

So i prepared a BR to run on sc_req_item table as below to clear the variables but its not working not sure what im doing wrong. Currently i have passed one of the attachment variable 'signed_subcontractor_agreement'.

Can you please help  me on this !!!

 

clearVariable('signed_subcontractor_agreement');


function clearVariable(variableName){

try{

var ritmSysID;
var ritm = new GlideRecord('sc_req_item');
ritm.addEncodedQuery('cat_item=b659d7721bf9d81010a4cbfe6e4bcb3a');
ritm.query();

while(ritm.next()){
ritmSysID = ritm.sys_id;
//gs.print('ritmSysID: ' + ritmSysID);

//use this sys_id to look up variable
var varTable = new GlideRecord('sc_item_option_mtom');
varTable.addQuery('request_item',ritmSysID);
varTable.addQuery('sc_item_option.item_option_new.name',variableName);
varTable.query();

while(varTable.next()){
//gs.print('Q: ' + varTable.sc_item_option.item_option_new.question_text + ' A: ' + varTable.sc_item_option.value + ' ');
varTable.sc_item_option.value = '';
varTable.update();

}
}
}

catch(ex){
gs.info('Exception is: ' + ex);
}
}

1 ACCEPTED SOLUTION

Slava Savitsky
Giga Sage

Dot-walking can only be used to read values from related records, but not for changing them. If you want to update a related record, you first need to grab its own GlideRecord object. Try this in your inner while loop:

var varRec = varTable.sc_item_option.getRefRecord();
varRec.value = '';
varRec.update();

 

Additionally, you should use:

ritmSysID = ritm.getValue('sys_id');

instead of:

ritmSysID = ritm.sys_id;

 

View solution in original post

1 REPLY 1

Slava Savitsky
Giga Sage

Dot-walking can only be used to read values from related records, but not for changing them. If you want to update a related record, you first need to grab its own GlideRecord object. Try this in your inner while loop:

var varRec = varTable.sc_item_option.getRefRecord();
varRec.value = '';
varRec.update();

 

Additionally, you should use:

ritmSysID = ritm.getValue('sys_id');

instead of:

ritmSysID = ritm.sys_id;