How to update the record in a custom table(u_terms_and_conditions) from widget editor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 08:54 AM
I have created a widget terms and conditions on accepting it will update the record of the user in u_terms_and_conditions and field u_accepted_or_rejected to true initially it will be false server side script and angular template is working fine but was unable to update the record from client side.
Client Script
Server Script
Angular Template
<div class="modal-header">
<h3 class="modal-title">Terms and Conditions</h3>
</div>
<div class="modal-body">
<p>Please read and accept the Terms and Conditions to proceed.</p>
<p>Your terms and conditions content goes here...</p>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="agree()">Agree</button>
<button class="btn btn-danger" ng-click="disagree()">Disagree</button>
</div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2025 06:58 AM
Hi @Deepak Panigrah ,
Possible Solutions:
Fix the $http.put Request
- Ensure the URL for updating the record is correctly formatted as /api/now/table/<table_name>/<sys_id>.
- Add proper headers (Content-Type: application/json) to the $http request.
- Pass the data object in the correct format, e.g., { u_accepted_or_rejected: true }.
Check Permissions
- Ensure the logged-in user has write access to the u_terms_and_conditions table.
- Verify that the appropriate roles and ACLs are configured for the /api/now/table endpoint.
Validate sys_id
- Confirm that the sys_id of the record being passed from the server-side script (c.data.recordSysId) matches an existing record in the u_terms_and_conditions table.
- Debug the sys_id being passed using console.log() in the client script.
Use Debugging Tools
- Check the Network tab in the browser developer tools to verify the API request and response.
- Look for HTTP error codes (e.g., 403 for permission issues or 404 if the record is not found).
Server-Side Validation
- Add logs in the server script to confirm the correct record is being queried and the sys_id is passed to the client.
Test the API Separately
- Use a tool like Postman or ServiceNow's REST API Explorer to test the /api/now/table/u_terms_and_conditions/<sys_id> endpoint with the same payload.
- Ensure the record is updated successfully outside the widget to isolate the problem.
AngularJS Scope Issues
- Confirm that $scope.agree is correctly bound in the modal. If there are any issues with the binding, the function may not execute properly.
If this answer helps you solve your query, please mark it as accepted and helpful.
Best Regards,
Siddhesh Jadhav