Add new RITM to existing REQ and update the new RITM Variables via a script

Daryn
Tera Contributor

I am trying to script a whay to add new RITMs to an existing request, but it does not seem to be working.  I got it to add a new RITM to the request, but the new RITM has the default variable values in it, and not the new ones.

 

my 4 variable in the RITM are:

request_type

hostname

alias

network_tier

 

 

My code is:

//create a new item in the request
var Req_SysID = 'b0f5bd85db83101080d984da0b961959';  //Hard code for testing
var CN = 'd04db306dba5501080d984da0b9619ca'; //sid for Catalog Item

var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(Req_SysID, CN, 1); // 1 is the qty  
reqHelper.rebalanceRequest(Req_SysID);  

//find the item and update its variables
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', Req_SysID);  
grReqItem.addQuery('cat_item', CN);
grReqItem.addQuery('parent','');
grReqItem.query();

gs.addInfoMessage('After ITEM Query - before variables');   //  Comment to see where the script is executing         

if(grReqItem.next()) {
    grReqItem.variables.request_type = 'test';  
    grReqItem.variables.hostname = 'host name'
    grReqItem.variables.alias = 'alias name';
    grReqItem.variables.network_tier = '24';
    grReqItem.parent = Req_SysID;

    grReqItem.update();
    gs.addInfoMessage('Variable IF Statement ran');  //Comment to see if the IF statement ran

}
 
 
Any suggestions would be appreciated.
9 REPLIES 9

Daryn
Tera Contributor

I tried it both ways - grReqItem.addNullQuery('parent') and grReqItem.addQuery('parent','').   Either way comes up with 174 on this request, even though there are now 213 RITMs in the request.

 

Using either code on new requests, or ever a couple requests I have with less than 10 RITMs, it works.  Seems to only be failing on the request with the high number of RITMs.  We are going to test this out and see if we hit a limit (possibly 174??).

1. Try once with the below queries only and check the row count. Remove the parent filter completely.

grReqItem.addQuery('request', Req_SysID);  
grReqItem.addQuery('cat_item', CN);

2. Have you tried on any other request having ritm count greater than 175? 

Regards,
Muhammad

Daryn
Tera Contributor

1 - Removing the parent filter completely gave us an accurate count of the RITMs on each request we ran it on, creating a new RITM as the code says.  HOWEVER, it failed to add the variable values on all the new RITMs.  Looks like we need the parent line for the variable add to work?  Leaving the parent line in, the RITM count is not accurate for most of the requests we tested it on.

 

2 - We upped the count on other requests and it works.  We even got one up to 252 RITMs, and it was adding more and changing the variables.  I went back to the original request, and it is still not working on this request.  We are thinking that with all our testing on that original request that something else is wrong with the request and not this code, as the code is working on other requests and new requests.

 

I think we got it working now.  Thanks for your help!

Daryn
Tera Contributor

1 - Removing the parent filter completely gave us an accurate count of the RITMs on each request we ran it on, creating a new RITM as the code says.  HOWEVER, it failed to add the variable values on all the new RITMs.  Looks like we need the parent line for the variable add to work?  Leaving the parent line in, the RITM count is not accurate for most of the requests we tested it on.

 

2 - We upped the count on other requests and it works.  We even got one up to 252 RITMs, and it was adding more and changing the variables.  I went back to the original request, and it is still not working on this request.  We are thinking that with all our testing on that original request that something else is wrong with the request and not this code, as the code is working on other requests and new requests.

 

I think we got it working now.  Thanks for your help!

Yeah, seems like something has broken on the existing requests/ritms. Maybe the state they are in not allowing variables to get updated.  

If you think the script is working then please mark the response as correct and helpful and close the thread. So that others can be benefited by this in the future.

Have a nice one 🙂

Thanks & Regards,

Sharjeel

Regards,
Muhammad