Map variable of record producer

Greg L
Tera Contributor

We are creating a record producer to capture defects, however we want to map the variables back to the defect record it creates, I know we need to do this in the record producer screp but just need some help with the logic, basically want to map the following:

 

requested_by to u_requested_by field on defect form

u_summary_of_the_defect to short_description field on defect form

u_impact_on_users to impact_on_users field on the defect form

u_priority to u_priority field on the defect form

We want to below all mapped to the Description field on the defect form however with headings and spacing in between.

 

Summary of the Defect:
u_summary_of_the_defect

 

Steps to Reproduce:
u_steps_to_reproduce

 

Expected Behavior:
u_expected_behavior

 

Actual Behavior:
u_actual_behavior


u_attachments (I'm assuming any attachments uploaded here will just automatically add as attachments to the defect form?

 

 

4 REPLIES 4

Barath P
Tera Guru

Hi @Greg L

To map the variables from your record producer to the defect form in ServiceNow, you'll need to use a script in the Record Producer's script field. Here's how you can structure it.

// Set fields on the defect record

current.u_requested_by = producer.requested_by;

current.short_description = producer.u_summary_of_the_defect;

current.impact_on_users = producer.u_impact_on_users;

current.u_priority = producer.u_priority;

// Attachments should automatically carry over if you are using out-of-the-box attachment functionality.


producer.variable_name: Retrieves the value from the record producer variables.

current.field_name: Maps the value to the target field on the defect form.

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Barath.P

 

Greg L
Tera Contributor

Thanks so much, how about the mapping to the Description as per the below:

 

We want to below all mapped to the Description field on the defect form however with headings and spacing in between.

 

Summary of the Defect:
u_summary_of_the_defect

 

Steps to Reproduce:
u_steps_to_reproduce

 

Expected Behavior:
u_expected_behavior

 

Actual Behavior:
u_actual_behavior

Barath P
Tera Guru

@Greg L 

You can try below script:

var description = '';
description += 'Summary of the Defect:\n';
description += producer.u_summary_of_the_defect + '\n\n';

description += 'Steps to Reproduce:\n';
description += producer.u_steps_to_reproduce + '\n\n';

description += 'Expected Behavior:\n';
description += producer.u_expected_behavior + '\n\n';

description += 'Actual Behavior:\n';
description += producer.u_actual_behavior + '\n\n';

// Set the description field on the defect form
current.description = description;

 

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Barath.P

Juhi Poddar
Kilo Patron

Hello @Greg L 

 

You can map the record producer variables to the defect record in the record producer script using server-side code. Here's an example of how you can handle this mapping:

Mapping Individual Fields: You'll directly assign the variables from the record producer to the fields in the defect record.

Mapping Multiple Variables to the Description Field: For this, you can concatenate the values from multiple variables with headings and line breaks.

Handling Attachments: Attachments uploaded to the record producer should automatically transfer to the defect record.

 

Here's the logic you need to add to the record producer script:

 

(function() {
    // Create a new defect record
    var defect = new GlideRecord('u_defect');  // Replace with your defect table name
    defect.initialize();

    // Map the individual fields
    defect.u_requested_by = producer.requested_by;
    defect.short_description = producer.u_summary_of_the_defect;
    defect.u_impact_on_users = producer.u_impact_on_users;
    defect.u_priority = producer.u_priority;

    // Concatenate fields for the Description field
    var description = '';
    description += 'Summary of the Defect:\n' + producer.u_summary_of_the_defect + '\n\n';
    description += 'Steps to Reproduce:\n' + producer.u_steps_to_reproduce + '\n\n';
    description += 'Expected Behavior:\n' + producer.u_expected_behavior + '\n\n';
    description += 'Actual Behavior:\n' + producer.u_actual_behavior + '\n\n';
    defect.description = description;

    // Insert the defect record
    var defectSysId = defect.insert();

    // Handle attachments (attachments automatically move to the created record)
    gs.addInfoMessage('Defect record created with ID: ' + defectSysId);
})();

 

 

Key Points:

  • Field Mapping: Fields like u_requested_by, short_description, and u_priority are mapped directly from the record producer to the defect form.
  • Description Field: The fields are concatenated with headings for the description field.
  • Attachments: As long as attachments are added to the record producer, they should automatically attach to the defect record.

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thank You

Juhi Poddar