- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 09:03 PM - edited 03-24-2024 09:03 PM
I'm new to learning ServiceNow, and I'm developing a mock PTO (Paid Time Off) application. When service catalog form is submitted, the startDate and endDate are not being recorded on the submitted form.
Below is the Script I am writing in record producer to populate. I am not sure if this is the correct approach.
(function executeRule(current, previous) {
// Get the start date and end date values from user input
var userInputStartDate = current.variables.start_date_pto;
var userInputEndDate = current.variables.end_date_pto;
// Convert user input strings to GlideDateTime objects
var startDate = new GlideDateTime(userInputStartDate);
var endDate = new GlideDateTime(userInputEndDate);
// Populate the start date and end date fields with user-provided values
current.start_date = startDate;
current.end_date = endDate;
})(current, previous);
producer.redirect = "redirect_url";
Record producer:
Here is the service catalog form:
Here is the form after submitting service catalog. (Where start and end dates are not being recorded.
I would be really helpful if someone helps me to fix or navigate me to correct path.
Thanks you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 09:23 PM
Hi @akhil_kusa,
You need to use the producer.variable_name instead of current.variables.variable_name;
Modify scripts as -
var userInputStartDate = producer.start_date_pto;
var userInputEndDate = producer.end_date_pto;
Scripts -
// Get the start date and end date values from user input
var userInputStartDate = producer.start_date_pto;
var userInputEndDate = producer.end_date_pto;
// Convert user input strings to GlideDateTime objects
var startDate = new GlideDateTime(userInputStartDate);
var endDate = new GlideDateTime(userInputEndDate);
// Populate the start date and end date fields with user-provided values
current.start_date = startDate;
current.end_date = endDate;
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 10:53 PM
you need not use scripting here.
You can directly use Map to Field feature and map the target field. simply select the target field where the variable value should be stored
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
03-24-2024 09:23 PM
Hi @akhil_kusa,
You need to use the producer.variable_name instead of current.variables.variable_name;
Modify scripts as -
var userInputStartDate = producer.start_date_pto;
var userInputEndDate = producer.end_date_pto;
Scripts -
// Get the start date and end date values from user input
var userInputStartDate = producer.start_date_pto;
var userInputEndDate = producer.end_date_pto;
// Convert user input strings to GlideDateTime objects
var startDate = new GlideDateTime(userInputStartDate);
var endDate = new GlideDateTime(userInputEndDate);
// Populate the start date and end date fields with user-provided values
current.start_date = startDate;
current.end_date = endDate;
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 10:53 PM
you need not use scripting here.
You can directly use Map to Field feature and map the target field. simply select the target field where the variable value should be stored
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