- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 07:32 AM
So I'm creating some of the backing fields for an order-able catalog item that'll go through a workflow. I'm trying to create the first step that generates/holds the request information.
One field that I need is an auto-incrementing value inside a certain table that simply tracks the Request ID and who ordered it.
Request Table
Header 1 | Header 2 |
---|---|
Request ID | Requested By |
So when a user wants to order an item, a record gets created in this table with the sys_id of who ordered it an it then increments the request ID by 1.
i.e:
- Will orders a new item,
- A new row is created in Request Table
- Request ID gets incremented by 1
- Requested By becomes the sys_id of the current user.
I then need to grab the new Request ID to insert it into a workflow payload (for a soap call).
Is there a way to do this in a workflow? My guess is that it needs to be done in a Run Script block, but I'm not sure on how to write it.
Here's what I have of the script so far,
/*
This script generates and stores the Request and Order/Instance numbers for the payload and the rest of the workflow.
*/
var workflow.scratchpad.requestNumber;
var workflow.scratchpad.orderNumber;
var workflow.scratchpad.instanceNumber;
var numbering = new GlideRecord('u_request_instance');
numbering.initialize();
numbering.u_requested_by = current.request.opened_by;
numbering.insert();
//I then need to grab that new request_id value from the u_request_instance table.
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 08:08 AM
Hi William,
var numbering = new GlideRecord('u_request_instance');
numbering.initialize();
numbering.u_requested_by = current.request.opened_by;
var sys_id = numbering.insert();
if(numbering.get(sys_id )) {
var request_id = numbering.request_id;
}
// request_id should hold your request id value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 08:08 AM
Hi William,
var numbering = new GlideRecord('u_request_instance');
numbering.initialize();
numbering.u_requested_by = current.request.opened_by;
var sys_id = numbering.insert();
if(numbering.get(sys_id )) {
var request_id = numbering.request_id;
}
// request_id should hold your request id value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 08:16 AM
Venkat,
Thanks for the assist! I'll give it a try and see what I come up with.
- Will
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 08:49 AM
Hello William,
I am just expanding your given script with few more statements to achieve this objective:
var numbering = new GlideRecord('u_request_instance');
numbering.initialize();
numbering.u_requested_by = current.request.opened_by;
var new_rec = numbering.insert() + '';
var req_id = ''
Option 1: Re-using the 'numbering' object it's already declared above
========
if(numbering.get(id)){
req_id = numbering.request_id + '';//here you find the request_id
}
Option 2: Same as Venkat suggested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 12:13 AM
Hello William,
Are you able to make any progress and achieve your objective?
Let us know when you need further assistance!