How to restrict Record creation into CMDB using Pattern Pre/Post Script from a value in payload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 02:03 AM
I Created a script to restrict records getting created but it is not working can someone help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 03:47 AM
Hi @manoj1 ,
To pass a payload to a Pre-Post Pattern script in ServiceNow, you'll need to use GlideAjax or GlideHTTPRequest to send data to the server.
Here's a basic outline of how you can do it:
1. Define a Pre-Post Pattern Script:
- In ServiceNow, go to System Definition > Script Includes.
- Create a new script include or edit an existing one.
- Define the function where you want to receive the payload.
2. Use GlideAjax to Send Data:
- In your client-side script (like in a UI Action or Client Script), use GlideAjax to send data to the server.
- Construct a JSON object or other suitable format to pass as your payload.
Example using GlideAjax:
```javascript
var ga = new GlideAjax('MyScriptInclude'); // 'MyScriptInclude' is the name of your script include
ga.addParam('sysparm_name', 'myFunction'); // Name of the function in your script include
ga.addParam('sysparm_myData', JSON.stringify(myData)); // 'myData' is your payload
ga.getXMLAnswer(myCallback);
```
3. Receive and Process the Payload in the Script Include:
- In your Pre-Post Pattern Script, access the data using `request.getParameter('sysparm_myData')`.
Example in your Script Include:
```javascript
var myFunction = function() {
var myData = request.getParameter('sysparm_myData');
// Process 'myData' as needed
};
```
Remember to replace `'MyScriptInclude'`, `'myFunction'`, and `'sysparm_myData'` with your actual script include name, function name, and parameter name.
Ensure that you handle any potential errors or exceptions properly in your scripts.
Please note that specific details might vary based on your ServiceNow instance version and configurations. Always refer to the official ServiceNow documentation and consult your instance's administrators for any customized configurations.
Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
Thanks
AJ
Linkedin Profile:- https://www.linkedin.com/in/ajay-kumar-66a91385/
ServiceNow Community Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 04:20 AM
Can we restrict record creation by using pattern pre/post scripts?