Start and end date fields are not populating after submitting record producer

akhil_kusa
ServiceNow Employee
ServiceNow Employee

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:

Screenshot 2024-03-24 at 22.29.39.png

 

 

Here is the service catalog form:

Screenshot 2024-03-24 at 22.57.54.png

Here is the form after submitting service catalog. (Where start and end dates are not being recorded.

 

Screenshot 2024-03-24 at 23.00.18.png

 

 

I would be really helpful if someone helps me to fix or navigate me to correct path.

 

Thanks you

 

@Ankur Bawiskar 

2 ACCEPTED SOLUTIONS

Sagar Pagar
Tera Patron

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

The world works with ServiceNow

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@akhil_kusa 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Sagar Pagar
Tera Patron

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

The world works with ServiceNow

Ankur Bawiskar
Tera Patron
Tera Patron

@akhil_kusa 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader