- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 03:10 PM
Afternoon.
Hoping to get some guidance on a client script to set due_date on a task from to 3 days prior to a variable date input on employee start date. Any assistance is appreciated as my initial attempts with onLoad client script haven't produced desired result.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 01:23 AM
Yes before will be good one.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 10:42 PM
If this is a Catalog Item, you should do this in the Flow or Workflow that runs for it.
If this is a Record Producer, you should do this in an insert before business rule.
It is easier to do it server side, plus it is not nice to modify values onLoad - it will be registered as a change and the user will get a data loss prompt even though no modification have been made - confusing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 11:59 PM - edited 02-03-2023 01:27 AM
Hi @Bcrant ,
Use before update/insert business rule on the sc_req_item table and give specific condition when it needs to update.
Use below script on business rule
(function executeRule(current, previous /*null when async*/ ) {
var startdate = current.variables.start_date;
var dt = new GlideTime();
var time = dt.getDisplayValue().split(' ')[1];//get time
var finaldatetime = startdate + ' ' + time; //it will give start date and time
var gdt = new GlideDateTime(finaldatetime); //using finaldatetime to subtract 3 days from start date
gdt.addDays(-3); //substract 3 days
current.due_date = gdt;//update on due date field
})(current, previous);
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 12:36 AM
current.update() - really?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 01:00 AM
Hi @-O- ,
I know it is not recommended but we can these lines when we can't avoid current.update()
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
ServiceNow Community MVP 2024.
Thanks,
Pavankumar