I want show message on load of from

Naresh43
Tera Contributor

Hello,

I have to show some field message on the form when loaded but in that it should get the value of 'program manger' and 'backup program manager' fields value I mean what it is having so, I have written on lead clent script in 'demand' table like g_form.showFieldMsg('checkbox field value','this field is to be ticked by person A and person B ',"info");

Instead of A and B it should pick the values in those 'program manager' and 'backup program manager' those are in 'program' table 

 

Thanks in advance ...

1 ACCEPTED SOLUTION

Hmm, understood the issue, there is limitation of using getReference method i.e. you can only access data up to one dot only.

e.g. grProgram.program_manager this works but when you use grProgram.program_manager.getDisplaValue(), it is going for second dot, that is you are trying to access another record data which actually does not exist on client side.

In this case you would need to use Display BR or GlideAjax.

Please use below Display BR and client script to achieve your goal.

Business Rule :

find_real_file.png

 

BR script :

find_real_file.png 

On load client script :

find_real_file.png

BR script for you to copy :

g_scratchpad.program_manager=current.primary_program.program_manager.getDisplayValue();
	g_scratchpad.backup_program_manager=current.primary_program.u_backup_program_manager.getDisplayValue();

Client script for you to copy:

function onLoad() {

    if (g_scratchpad.program_manager == "") {
        g_form.showFieldMsg('u_program_manager', 'This field is to be ticked by person ' + g_scratchpad.backup_program_manager);
    } else if (g_scratchpad.backup_program_manager == "") {
        g_form.showFieldMsg('u_program_manager', 'This field is to be ticked by person ' + g_scratchpad.program_manager);
    } else {
        g_form.showFieldMsg('u_program_manager', 'This field is to be ticked by person ' + g_scratchpad.program_manager +
            '\n ' + g_scratchpad.backup_program_manager);
    }

}

I haven't tested it practically but I am sure this would work, change field names properly if required.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

13 REPLIES 13

Abhijit4
Mega Sage

Hi,

You can use below approach

1. Write Display BR and store program manager, backup program manager in g_scratchpad object and access the same on client script show it in error message.

2. You can use GlideAjax to get program manager, backup program manager name and show it in error message.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

If those values are already there on the form then you could directly use below,

g_form.showFieldMsg('checkbox field value','this field is to be ticked by person '+g_form.getDisplayBox("program_manager").value+'and person '+g_form.getDisplayBox("backup_program_manager").value,"info"); //change field names accordingly

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hello Abhijit, Is not possible on load client script to show that message and it should have that values

Hi Naresh,

Since you have that data in reference field its stored on server not on client side there fore you would need to make server call to get that data.

If you have program field which is referring to program table then you can also use getReference method to get that data like below.

var grProgram=g_form.getReference('program_field_name',showErrorMessage);

function showErrorMessage(grProgram) { //reference is passed into callback as first arguments

g_form.showFieldMsg('checkbox field value','this field is to be ticked by person'+grProgram.program_manager_field_name+'and person'+grProgram.backup_program_manager_field_name);

}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hello Abhijit Like if I use this script I am getting sysids I need values in that fields and one more thing like in these two fields like program manager or back-up program manager if any one is empty so it should not displayed anything and it will come A/B