Custom scripted Rest API for record producer

GB14
Kilo Patron

I am wondering if someone can assist with script to post a record producer. 

We want this scripted rest API for just 1 record producer and only 5 fields. 

 

I have done for the incident but have no knowledge on how to create one for the record producer. How to call the record producer and variables etc. 

 

Any guidance will be appreciated. 

 

Thanks,
G

1 ACCEPTED SOLUTION

As an FYI, that sort of information is beneficial to include in your original question in future. 

 

Similar to the REST API, there is an js API you can use. CatItem | ServiceNow Developers. It can be combined with a scripted REST API.

View solution in original post

7 REPLIES 7

Sohail Khilji
Kilo Patron
Kilo Patron

HI @GB14 ,

 

try this :

 

for variables you can try this :

var variable1 = body.variable1;

var variable2 = body.variable2;

 

and use setvalue to set the value to variables...

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    // Parse the incoming request body
    var body = request.body.data;
    var short_description = body.short_description;
    var description = body.description;
    var producer = new GlideRecord('my_record_producer_table');
    producer.initialize(); 
    producer.setValue('short_description', short_description);
    producer.setValue('description', description);
    var producerID = producer.insert();

    if (producerID) {
        response.setStatus(201);
        response.setBody({
            "status": "success",
            "message": "Record producer created successfully",
            "producerID": producerID
        });
    } else {
        response.setStatus(500); 
        response.setBody({
            "status": "error",
            "message": "Failed to create record producer"
        });
    }
})(request, response);

 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

@Sohail Khilji  Let me test it and I will share an update on this. 

@Sohail Khilji if I add the record Item table, a new record item is getting inserted in the catalog items but not the record it self. 

Is there any way to target the item with sys_id like the OOB API instead of table gliderecord? Thanks

Kieran Anson
Kilo Patron

Have you considered using the OOB Record Producer REST API?