How do I insert a record into a table and grab values from that specific record?

willkara
Kilo Contributor

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 1Header 2
Request IDRequested 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:

  1. Will orders a new item,
  2. A new row is created in Request Table
    1. Request ID gets incremented by 1
    2. 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.

1 ACCEPTED SOLUTION

venkatiyer1
Giga Guru

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


View solution in original post

7 REPLIES 7

willkara
Kilo Contributor

Hey everyone! I'm still moving towards testing out the solutions and will hopefully have a working one by the end of the day today.


willkara
Kilo Contributor

Letting everyone know that I'm still looking into it, just got caught up on some other issues! I'll update it as soon as I implement it.


lks
ServiceNow Employee
ServiceNow Employee

Thank you for updating William, I appreciate your accountability 🙂