Search and update record widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2025 11:36 PM
I am looking for a widget using which I can search for a record from custom table, once the record is populated I need to have a submit button. Which will update the opened record.
I tried initially with record producer, with client script I populated the record details. It works with onchange. My issue over here is when user search for the record and directly try to submit which out giving time to validate it.
Any suggestions on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2025 11:45 PM
hi @ImranrasheeM ,
You can insert a record using below code. Note that I have made slight changes in the HTML as it did not include ng-model first. Also, this code is might not be following high coding standards, but will work, please make changes accordingly. I would also suggest you to rename your input tag Id's so that they are much more readable and make the UI responsive if this is actually going into production environment.
HTML Code:
<div class="widget-container"> <div class="widget"> <h2>Widget Input Form</h2> <div> <div class="form-group"> <label for="input1">Monday: </label> <input type="text" id="input1" ng-model="c.data.input1" placeholder="Enter Value"> </div> <div class="form-group"> <label for="input2"></label> <input type="text" id="input2" ng-model="c.data.input2" placeholder="Enter Value"> </div> <div class="form-group"> <label for="input3"></label> <input type="text" id="input3" ng-model="c.data.input3" placeholder="Enter Value"> </div> <div class="form-group"> <label for="input4"></label> <input type="text" id="input4" ng-model="c.data.input4" placeholder="Enter Value"> </div> <div class="form-group"> <label for="input5"></label> <input type="text" id="input5" ng-model="c.data.input5" placeholder="Enter Value"> </div> <button type="submit" ng-click="c.addRecord()">Submit</button> </div> </div> </div>
Client Controller:
api.controller=function($scope) { /* widget controller */ var c = this; c.addRecord = function() { alert($scope.c.data.input1); c.data.input1 = $scope.c.data.input1; c.data.input2 = $scope.c.data.input2; c.data.input3 = $scope.c.data.input3; c.data.input4 = $scope.c.data.input4; c.data.input5 = $scope.c.data.input5; c.data.action = "ACTION" c.server.update().then(function(response){ alert("Thank You for submitting the record"); }) } };
Server Script:
(function() { if(input && input.action=='ACTION'){ var insertRecord = new GlideRecord("table_name"); insertRecord.initialize(); insertRecord.field_name = input.input1; insertRecord.field_name = input.input2; insertRecord.field_name = input.input3; insertRecord.field_name = input.input4; insertRecord.field_name = input.input5; insertRecord.insert(); gs.addInfoMessage('Record Inserted'); } })();
If you feel this has helped you a bit, you may mark the answer as helpful or accept it as a solution.
Regards,
Abin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2025 12:59 AM
@AbinC I think your widget code helps with record insertion. So here we are looking for a concept like a custom table having a record with passcode field. User will enter the passcode, based on that we will show them with the record. Once they validate it and click on confirm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2025 12:14 AM
you can use either record producer to update
OR
you can ask user to raise a RITM and submit request, that catalog item will have variables to select the Record, fields to be updated
Once RITM is generated you can write script to update the record
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2025 12:58 AM
@Ankur Bawiskar : Thanks for your reply. So here we are looking for a concept like a custom table having a record with passcode field. User will enter the passcode, based on that we will show them with the record. Once they validate it and click on confirm.