Widget is not updating the date selected in the Widget on the target record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2024 12:31 AM
Morning, I am trying to create a widget that wil allow an end user to update a date field on a RITM. I have based the widget using script from the OOB "Update Watchlist" widget, but I cannot get the date entered in the widget to update the target record. By way of a test, I did add in a line of code just to enter the words "Script ran" , which does update after the button is pressed. So it just seems to be the date value that is not getting passed accross,
Here is my Script
HTML:-
<div class="panel panel-primary b">
<div class="panel-heading">
<h3 class="panel-title pull-left">
${Colleagues Leave Date}
</h3>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<div class="text-center text-italic text-muted">
<sp-date-picker field="u_colleagues_leaving_date_and_time"sn-include-time="true"></sp-date-picker>
</div>
</div>
<button type="button" class="btn btn-warning btn-block" ng-click="c.updatedate('updatedate')">Update Leave Date</button>
</div>
CSS:-
CLIENT SCRIPT:-

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2024 01:21 AM
Hey,
When posting code on the community, it'll be easier for us to read if you wrap the content in a code sampe (image below)
In regards to your issue, a couple code-smells to tidy up to avoid possible collisions:
- Try to avoid using "gr" as a variable name. Variables are global and it's more than likely that SN have used "gr" to store a value which you could overwrite
- Use getters and setters rather than directly assigning a value. Although SN tries to be helpful and understand your intent, it can lead you to running into some unexpected behaviour
- When setting date/time field values, you either need to to set it using the system date/time format or the users (the latter requiring the use of setDisplayValue() rather than setValue())
(function() {
var table = $sp.getParameter('table')
var sys_id = $sp.getParameter('sys_id')
var currentRecordcurrentRecordGR = new GlideRecord(table);
if (currentRecordGR.get(sys_id)) {
data.displayValue = currentRecordGR.getDisplayValue('u_colleagues_leaving_date_and_time');
data.value = currentRecordGR.getValue('u_colleagues_leaving_date_and_time');
}
if (input && input.action) {
var action = input.action;
if (action == 'updatedate') {
currentRecordGR.setValue('u_colleagues_leaving_date_and_time' , input.updatedate);
currentRecordGR.setValue('u_uipath_comment' , "script ran");
currentRecordGR.update();
gs.addInfoMessage("Leave Date updated ");
}
}
})();
Change your usage of the spDatePicker directive to directly bind the value such as
<sp-date-picker ng-model="data.u_colleagues_leaving_date_and_time" sn-include-time="true"></sp-date-picker>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2024 06:02 AM
Hi Kieran
Thanks for your response, Even following your advice and script, the Widget still does not update the date field