Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Triggering custom event from Scripted REST API

Raji9
Tera Expert

Hi ,

 

Can I trigger a custom event from Scripted REST API?  Is there nny examples?

 

Thanks

Raji

2 REPLIES 2

John Zhang1
Kilo Patron
Kilo Patron

You use the following script:  This is doc for your reference

 

eventQueue(String name, Object gr, String option1, String option2, String event_queue) 

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Raji9 ,
I trust you are doing great.
Yes, it is possible to trigger a custom event from a Scripted REST API in ServiceNow. To achieve this, you can make use of the GlideSystem's "eventQueue" method. Here's an example code snippet that demonstrates how to trigger a custom event:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    // Your code logic here

    // Triggering a custom event
    gs.eventQueue('my_custom_event', current, 'additional_data');

    // Return the response
    return response;
})(request, response);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi