Converting Name into sys_id in JSON

vpm
Tera Contributor

Hi,

I am trying to create catalog request using this REST API - /api/sn_sc/servicecatalog/items/{sys_id_item}/order_now.

Catalog is getting created successfully when I am passing this query parameter   -

{"sysparm_quantity":"1",

"variables": {"requested_for":"c72b38bb4f59a600db4315924210c745"}

But instead of sys_id of 'requested_for', I want to pass name of the user.

How I can convert name into sys_id before inserting into the table.

thanks in advance!!

Vidyapati

1 ACCEPTED SOLUTION

Hi Vidyapati,



You need not to create any staging table. Please follow the below steps to meet your requirement   :-




1. Go to table "sys_ws_operation" and open "Buy Item" record.


find_real_file.png



2. Click on the "here" text to edit the script as shown below in the screen shot :-



find_real_file.png



3. Scroll down to the script area. Below is the screen shot of the change that you need to make in the script. Add the code which is inside red box in your script and save the changes.



find_real_file.png



4. Now call your REST api and test.




Let me know if this works for you. However I tested this and is working on my instance.



Please mark helpful/correct if this solves your issue/requirement.


View solution in original post

7 REPLIES 7

Sharique Azim
Mega Sage

HI,


Vidyapati Mishra wrote:




How I can convert name into sys_id before inserting into the table.



How can you get the sys_id of the record, unless its fetched?


If sys_id is to be passed it has to be static.


Hi as you are direct Rest API there is no need for conversion to sys_id



You can send the name of the user in the payload, if the exact name matches in the user table the record is created with the users name. If not the requested for value will be empty.



Please like, Mark helpful/Correct based on the impact of the response.


kamlesh kjmar
Mega Sage
Mega Sage

Hi Vidyapati,



Effect of this change is limited to REST call only and it will work for all the catalog items. If you send any user name, it will work. Even if you send sys_id of the user it will work.