- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2014 02:21 AM
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();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2014 11:47 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2014 03:18 AM
tried this?
var req= current.request.getRefRecord();
req.requested_for= '01f3aba9141c390048f5dab33584817c';
req.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2014 03:56 AM
Hello Sanjeev,
I don't see any error in your script and it should work fine.
updatereq();
function updatereq()
{
var req_no= current.request;
var req = new GlideRecord('sc_request');
req.addQuery('sys_id', req_no);
req.query();
if(req.next()){
req.requested_for= '01f3aba9141c390048f5dab33584817c'; //Double check the sysid of the user
req.update();
}
}
NOTE: Make sure that you remove the line "req.update();" in case you are using the before business rule.
Please let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2014 06:29 AM
Hi Kalai,
Your code is working, but its generating two request with same request no and its getting approved automatically.
So, basically it dint worked for me

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2014 07:02 PM
It should not create duplicate request. You do have some business.rul that is inserting a duplicate record. Use debug business rule details to find it.