How to add a link in a warning message?

snow_beginner
Mega Guru

Hi,

So the requirement is that when an incident changes priority to critical, a warning message comes up and it needs to have a clickable link which leads to a knowledge article. I have made a client script for this but not sure how I can add the url to the Knowledge article. What am I doing wrong here? If I remove the var url alltogether than everything works fine. If I add it before the if statement it still does not work.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
       if (isLoading || newValue === '') {
           return;
       }

      
       if (newValue == 1) {

 var url = <a href = "https://lbg.service-now.com/it_lbg?id=kb_article&sysparm_article=KB0078495"> KB0078495 - critical incident guidance </a>
           var res = confirm("Warning! Creating an incident with critical priority will automatically start the major incident process. Truly critical incidents are extremely rare so please ensure you fully understand the implications before submitting an incident with that priority. See" + url);
           if (res == true) {
               return true;
           } else {
               //g_form.setValue('priority',oldValue);
               g_form.setValue('impact', g_scratchpad.impact);
               g_form.setValue('urgency', g_scratchpad.urgency);

           }
       }
   }

 

1 ACCEPTED SOLUTION

Hi,

Hello, we have some problems using & because the code understands that you will write some Unicode like &lt; and unfortunately, we couldn't get around it.

To redirect to an article you can use the link '/kb_view.do?sys_kb_id=c85cd2519f77230088aebde8132e70c2'
It will redirect on the platform and not on the portal

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    if (newValue == '1') {
        var text = "Warning! Creating an incident with critical priority will automatically start the major incident process. Truly critical incidents are extremely rare so please ensure you fully understand the implications before submitting an incident with that priority. See &#160; <a href='/kb_view.do?kb_article=KB99999999 ' target='_blank' > KB99999999 - Microsoft Outlook Issues </a>";

        var gm = new GlideModal ("glide_confirm_basic", true, 600);
        gm.setTitle("Test title");
        gm.setPreference("title", text);
        /* gm.setPreference("onPromptComplete", function() {
             alert("You clicked on 'Ok'")
         });*/
        gm.setPreference("onPromptCancel", function() {
            //alert("You clicked on 'Ok'")
            g_form.setValue('impact', g_scratchpad.impact);
            g_form.setValue('urgency', g_scratchpad.urgency);
        });
		
        gm.render();
    };

}

 

 

Vanderlei_0-1697643078140.pngVanderlei_1-1697643096094.png

If my answer helped you, please mark my answer as helpful.

 

Vanderlei Catione Junior | LinkedIn

Senior ServicePortal Developer / TechLead at The Cloud People

View solution in original post

7 REPLIES 7

psphanindrakuma
Tera Guru
Tera Guru

@snow_beginner 

 

You can't put URL in browser confirm. Instead you can use UI page for this. Create a UI page and call via GlideModal.

 

Please mark my answer as correct and helpful if it solves your issue

 

Thanks,

Phanindra.

 

Vanderlei
Mega Sage

Hi @snow_beginner and @psphanindrakuma

The best way to achieve your goal would be using the modal glide, here is an example of code that you can use.

Note that I needed to replace the & with %26 and the space with &#160;

 

 

 

function onLoad() {
    //Type appropriate comment here, and begin script below

    var text = "Warning! Creating an incident with critical priority will automatically start the major incident process. Truly critical incidents are extremely rare so please ensure you fully understand the implications before submitting an incident with that priority. See &#160; <a href='https://lbg.service-now.com/it_lbg?id=kb_article%26sysparm_article=KB0078495' target='_blank' > KB0078495 - critical incident guidance </a>";

    var gm = new GlideModal("glide_confirm_basic", true, 600);
    gm.setTitle("Do you want to create a major incident?");
    gm.setPreference("title", text);
     gm.setPreference("onPromptComplete", function() {
         g_form.save()//Save Record
     });
    gm.setPreference("onPromptCancel", function() {
        g_form.setValue('impact', g_scratchpad.impact);
        g_form.setValue('urgency', g_scratchpad.urgency);
    });
    gm.render();
}

 

 

 


Note that I didn't need to create a customized UI Page to achieve the objective following good practices using ootb

 

If my answer helped you, please mark my answer as helpful.

 

Vanderlei Catione Junior | LinkedIn

Senior ServicePortal Developer / TechLead at The Cloud People

Hi, thanks so much for helping with this.

 

But this is an onLoad client script, so the warning comes up on loading the incident page. I changed it to an onChange client script and that's working but with an issue.

 

As soon as I change the 'Impact' OR 'Urgency' field, the warning comes up. It should come up when both of these values change to high so that priority changes to Critical. How can that be fixed?

Hi,

I made some changes to the code to get the result you want.
We could create two onChange Client Scripts for the urgency and impact fields, however, we can use the priority field, as the priority will be 1- Critical if the impact and urgency are high.

So just add a client script on change in the priority field and we can get the expected result

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    if (newValue == '1') {
        var text = "Warning! Creating an incident with critical priority will automatically start the major incident process. Truly critical incidents are extremely rare so please ensure you fully understand the implications before submitting an incident with that priority. See &#160; <a href='https://lbg.service-now.com/it_lbg?id=kb_article%26sysparm_article=KB0078495' target='_blank' > KB0078495 - critical incident guidance </a>";

        var gm = new GlideModal("glide_confirm_basic", true, 600);
        gm.setTitle("Test title");
        gm.setPreference("title", text);
        /* gm.setPreference("onPromptComplete", function() {
             alert("You clicked on 'Ok'")
         });*/
        gm.setPreference("onPromptCancel", function() {
            //alert("You clicked on 'Ok'")
            g_form.setValue('impact', g_scratchpad.impact);
            g_form.setValue('urgency', g_scratchpad.urgency);
        });
		
        gm.render();
    };

}

 

 

Vanderlei_0-1697635903949.png

 

If my answer helped you, please mark my answer as helpful.

 

Vanderlei Catione Junior | LinkedIn

Senior ServicePortal Developer / TechLead at The Cloud People