retrieve a line from description

rajesh44853
Tera Contributor

Hello

I am working on getting a line extraxted from description field on  a changed and detials looks someting like this mentioned below

What i am looking fir is retrieve line which says Provision Type : Standard

 

Requested For : Test user
Requested By : Test user
Requested For's Manager : Jyoti Das
Best Method of Contact : test
IsCGP : true
Requested By Date : 2023-09-13 07:58:34
Configuration Item : CI name
Application contact : Approval User1
Location : ABC
Nautical : Shore
Daptiv Workspace / Project Name : s
Car No : s
OS Type : Windows
Provision Type : Standard
Environment Type : Production
Short Description : test
Business Reason for Request : stes
Additional Comments : test

 

tried using

 

var gr = new GlideRecord('change_request');
gr.get('29d6e06447017154267b9763636d4393');
var abc = gr.description;
var final1 = abc.indexOf("Provision Type : Standard");
 
and 
 

var gr = new GlideRecord('change_request');
gr.get('b6f50cb69749f1509a4216a00153af03');

var abc = gr.description;
var rajesh = abc.split('\n');

 

 

but both fails stating invalid object

 

4 REPLIES 4

Chaitanya Redd1
Tera Guru

Hi,

Please try below code.

var gr = new GlideRecord('change_request');
if (gr.get('sys_id', 'your_change_request_sys_id')) {
    var description = gr.description.toString();
    // Now, you can work with the description field
    var lines = description.split('\n');
    for (var i = 0; i < lines.length; i++) {
        if (lines[i].indexOf('Provision Type : Standard') !== -1) {
            gs.info('Found line: ' + lines[i]);
            break; // Exit the loop once found
        }
    }
} else {
    gs.error('Change request not found');
}

Missed to inform this is in the Workflow

Hi,

Please try below code run script activity

var gr = new GlideRecord('change_request');
if (gr.get('29d6e06447017154267b9763636d4393')) { // Replace with the correct change request ID
    var description = gr.getValue('description');
    var lines = description.split('\n');

    for (var i = 0; i < lines.length; i++) {
        if (lines[i].indexOf('Provision Type : Standard') !== -1) {
            var provisionTypeLine = lines[i];
            break; // Exit the loop once the line is found
        }
    }

    if (provisionTypeLine) {
        // You've found the line, and it's stored in provisionTypeLine
        gs.info("Provision Type Line: " + provisionTypeLine);
    } else {
        gs.info("Provision Type Line not found");
    }
} else {
    gs.info("Change request not found");
}

 

OlaN
Giga Sage
Giga Sage

Hi,

Try something like this, just change the config to fit your needs:

var incGR = new GlideRecord('incident');
if(incGR.get('3609a3b08719351025c58409cebb3543'){
    var desc = incGR.getValue('description');
    var arrayDesciption = desc.split('\n');
    for (var i=0; i<arrayDesciption.length; i++){
       //gs.info('Desc line: ' + arrayDesciption[i]);
       if(arrayDesciption[i].indexOf('Provision Type :') > -1){
           gs.info('Found it: ' + arrayDesciption[i])
        }
    }
}