Not able to Query a table successfully

sanjeev28 k
Giga Expert

Hi,

 

I am taking the request no. from a request item (sc_req_item) table based on some conditions and then querying that request no. into request table (sc_request) and then assigning a static value of a particular user to the field of requested_for'. But Its not getting into req.next() loop. and req.query is giving a "undefined " response which I checked in logs. Please Help.

 

 

var req_no= current.request;                   // getting a request no. from sc_req_item table

 

var   req = new GlideRecord('sc_request');

 

req.addQuery('sys_id', req_no);

req.query();                   // showing   as   'undefined' response in logs

if(req.next()){               // showing   as   'false' response in logs

req.requested_for= '01f3aba9141c390048f5dab33584817c';     // Assigning a static user sys_id to requested_for field

req.update();

1 ACCEPTED SOLUTION

Hi Kalai, i got my answer, and thanks for your kind support,


I just removed req.update(); from your code. and used only the below code. And now I am getting only single request.




var req= current.request.getRefRecord();


req.requested_for= '01f3aba9141c390048f5dab33584817c';



Thanks kalai and pradeep


View solution in original post

30 REPLIES 30

sc_req_item and its after only


I think you are missing something here... an update statement will not create a duplicate request... i tried this in demo and it is working fine.. attaching the xml of the business rule that I created on demo ... import this in any demo instance and check...


change the sys_id in the script as per your requirement...


Hi Kalai,


I guess you are right, It was getting auto approved because the static user was not having manager. so it was my mistake.


but the case of creation of two request is still a mystery for me.


and the below script is only running when I will choose the insert   & after option and nothing else


var req= current.request.getRefRecord();


req.requested_for= '01f3aba9141c390048f5dab33584817c';


req.update();


Hi Kalai, i got my answer, and thanks for your kind support,


I just removed req.update(); from your code. and used only the below code. And now I am getting only single request.




var req= current.request.getRefRecord();


req.requested_for= '01f3aba9141c390048f5dab33584817c';



Thanks kalai and pradeep


sanjeev28 k
Giga Expert

Hi Pradeep,


I am using after business rule but its really not working