The CreatorCon Call for Content is officially open! Get started here.

Auto Populate short description and description fields of a problem task from Template

YamunaRaniK
Giga Contributor

Hi Everyone,

 

I have a requirement to Auto populate Short description and Description fields of a Problem Task whose type is Risk Accepted (Like Root Cause Analysis) from a pre-defined template.

 

I tried using Business and Client script + script include but nothing is working as expected. 

I tried to query the fields of my template which is present in sys_template table in background script but nothing is coming as result.

 

Does anyone know the behavior of sys_template table, can anyone help me on this requirement.

 

Thanks in advance.

2 ACCEPTED SOLUTIONS

@YamunaRaniK 

I don't think it's a valid requirement to use script to set the fields when you can easily do this with templates.

But if you still require then you need to grab the encoded string from template, do string manipulation and then grab the short description and description and then set it

Something like this

AnkurBawiskar_0-1761124273776.png

var gr = new GlideRecord("sys_template");
gr.addQuery("name", "value");
gr.query();
if (gr.next()) {
    var input = gr.template.toString();

    var parts = input.split('^');
    var shortDescription = '';
    var description = '';
    for (var i = 0; i < parts.length; i++) {
        var keyValue = parts[i].split('=');
        if (keyValue[0] === 'short_description') {
            shortDescription = keyValue[1] || '';
        }
        if (keyValue[0] === 'description') {
            description = keyValue[1] || '';
        }
    }

    current.short_description = shortDescription;
    current.description = description;
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

Syed14
Mega Guru

If you want to auto populate fields when form loads or any specific field changes, it can easily be achieved by using client script. According to your condition, set value of the description and short description fields on the form. Why are you using template?

If you need help in client script, let me know.

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@YamunaRaniK 

so when template is applied you want to Auto populate short description and Description?

why not set those in template itself?

what's your business requirement?

share screenshots etc

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hi @Ankur Bawiskar ,

 

Thanks for the response.

 

I am attaching the template I have created and the business rule which is written on problem_task table before insert. The background script that I tried to pull all the names of the sys_template returning some other table.

 

The Short description and description need to auto populate when a problem task is getting created.

 

Any suggestions on it will be very helpful.

@YamunaRaniK 

you already have short description and description in template.

when you apply template those 2 fields are not getting auto-populated?

how are you applying the template? share screenshots.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @YamunaRaniK 

Template means to populate the preloaded values into the actual fields. If the template already has values, they get automatically mapped and copied to the corresponding fields when you apply the template. There’s no difference or additional logic needed around it — it’s all out of the box (OOTB).

 

https://youtu.be/cXbqLUnnfZQ

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************
Disclaimer: These videos are from my training batch. These videos did not promote any ServiceNow Sales pitch or marketing. These videos are only for knowledge purposes. LinkedIn:https://www.linkedin.com/in/atulgroverservicenowconsultant Redistribution or copying of functionality is not allowed!