task isn't generating

PK14
Kilo Guru

Hi SN experts,

I am stuck in generating task using below run script code in workflow. Requirement is, if user belongs to ABC and XYZ BU (business unit) or has email containing xyz in it then should create a ticket. 

Currently ticket isn't being created for regular user but it's also not creating for given condition. 

mail = current.variables.requested_for.email;
secondary_email = current.variables.requested_for.u_email;
num = current.variables.requested_for.employee_number;
title = current.variables.requested_for.title.getDisplayValue();
manager = current.variables.requested_for.manager.getDisplayValue();
department = current.variables.requested_for.department.getDisplayValue();
var BU = current.variables.requested_for.u_business_unit;

if ((BU == '036281df1b8b00108f2f0d4acd4bcbd8' ||
    BU == 'cc1723c80f32070430f905cce1050ec3') &&
    (mail.toLowerCase().indexOf("xyz") !== -1 ||
    secondary_email.toLowerCase().indexOf("xyz") !== -1))

{
    var gr21 = new GlideRecord('sc_task');
    gr21.initialize();
    gr21.short_description = 'xyzGmailSuspend for ' + name;
    gr21.assignment_group = '6ae65e6e1b7cb5500b5c42ebbc4bcb74'; /
    gr21.assigned_to = '';
    if (secondary_email == '') {
        gr21.description = 'Name: ' + name + '\n' +
                           'Email: ' + mail + '\n' +
                           'Title: ' + title + '\n' +
                           'Manager: ' + manager + '\n' +
                           'Business Unit: ' + business_unit + '\n' +
                           'Department: ' + department;
    } else {
        gr21.description = 'Name: ' + name + '\n' +
                           'Email: ' + mail + '\n' +
                           'Secondary Email: ' + secondary_email + '\n' +
                           'Title: ' + title + '\n' +
                           'Manager: ' + manager + '\n' +
                           'Business Unit: ' + business_unit + '\n' +
                           'Department: ' + department;
    }
    gr21.request_item = current.sys_id;
    gr21.insert();
} else {
    gs.info('Condition not met. No ticket created.');
}

Please assist on this. 
3 REPLIES 3

Bhavya11
Kilo Patron

hi @PK14 ,

 

you're using name in gr21.short_description = 'xyzGmailSuspend for ' + name;, but it is not defined anywhere in the script. please define it and validate it

 

Please mark helpful & correct answer if it's really worthy for you.

 

 

Thanks,

BK

PK14
Kilo Guru

Hi @Bhavya11 
I missed to add it here, but that's already there in the script. 


 

Bhavya11
Kilo Patron

Hi @PK14 ,

 

even business_unit also because you defined it as BU 

 

var mail = current.variables.requested_for.email;
var secondary_email = current.variables.requested_for.u_email;
var num = current.variables.requested_for.employee_number;
var title = current.variables.requested_for.title.getDisplayValue();
var manager = current.variables.requested_for.manager.getDisplayValue();
var department = current.variables.requested_for.department.getDisplayValue();
var BU = current.variables.requested_for.u_business_unit.getDisplayValue(); // Assuming you need the display value of Business Unit
var name = current.variables.requested_for.getDisplayValue(); // Assuming you need the display name

if ((BU == '036281df1b8b00108f2f0d4acd4bcbd8' ||
    BU == 'cc1723c80f32070430f905cce1050ec3') &&
    (mail.toLowerCase().indexOf("xyz") !== -1 ||
    secondary_email.toLowerCase().indexOf("xyz") !== -1))
{
    var gr21 = new GlideRecord('sc_task');
    gr21.initialize();
    gr21.short_description = 'xyzGmailSuspend for ' + name;
    gr21.assignment_group = '6ae65e6e1b7cb5500b5c42ebbc4bcb74';
    gr21.assigned_to = '';
    
    if (secondary_email == '') {
        gr21.description = 'Name: ' + name + '\n' +
                           'Email: ' + mail + '\n' +
                           'Title: ' + title + '\n' +
                           'Manager: ' + manager + '\n' +
                           'Business Unit: ' + BU + '\n' + // Updated to use BU
                           'Department: ' + department;
    } else {
        gr21.description = 'Name: ' + name + '\n' +
                           'Email: ' + mail + '\n' +
                           'Secondary Email: ' + secondary_email + '\n' +
                           'Title: ' + title + '\n' +
                           'Manager: ' + manager + '\n' +
                           'Business Unit: ' + BU + '\n' + // Updated to use BU
                           'Department: ' + department;
    }
    gr21.request_item = current.sys_id;
    gr21.insert();
} else {
    gs.info('Condition not met. No ticket created.');
}