proper syntax for UI macro alert using gs.getMessage

robertsduca
Giga Contributor

Can anyone please assist in converting the following into an alert using ${gs.getMessage('message');}   so we can display translated values?

I highlighted in red the values I have messages for in the message table to substitute for.

Thanks in advance for the help!!

<script>

                      function checkMandatorySubmit(rec){

                              var storeUser = $[jvar_store_user];

                              if(storeUser)

                                      gsftSubmit(rec);

                              var manFields = '';

                              var pcnum = $[jvar_pcnum];

                              var approver = $[jvar_approver];

                              var store = $[jvar_store];

                              var secapprover = $[jvar_approver2];

                              var location = gel('location').value;

                              var cube = gel('cube_number').value;

                              var proj = gel('project').value;

                              var art = gel('artemis_number').value;

                              var count = 0;

                              if(location == ''){

                                      if(count > 0){

                                              manFields += ', Office Location';

                                      }

                                      else{

                                              manFields += 'Office Location';

                                      }

                                      count++;

                              }

                              if(pcnum == true){

                                      var pc = gel('pc_tag_num').value;

                                      if(pc == ''){

                                              if(count > 0){

                                                      manFields += ', PC Tag #';

                                              }

                                              else{

                                                      manFields += 'PC Tag #';

                                              }

                                              count++;

                                      }

                              }

                              if(approver == true){

                                      var app = gel('approver').value;

                                      if(app == ''){

                                              if(count > 0){

                                                      manFields += ', Approver';

                                              }

                                              else{

                                                      manFields += 'Approver';

                                              }

                                              count++;

                                      }

                              }

                              if(store == true){

                                      var str = gel('store').value;

                                      if(str == ''){

                                              if(count > 0){

                                                      manFields += ', Store';

                                              }

                                              else{

                                                      manFields += 'Store';

                                              }

                                              count++;

                                      }

                              }

                              if(secapprover == true){

                                      var app2 = gel('approver2').value;

                                      if(app2 == ''){

                                              if(count > 0){

                                                      manFields += ', Second Approver';

                                              }

                                              else{

                                                      manFields += 'Second Approver';

                                              }

                                              count++;

                                      }

                              }

                              if(proj == 'yes') {

                                  if(art == ''){

                                      if(count > 0){

                                              manFields += ', Artemis #';

                                      }

                                      else{

                                              manFields += 'Artemis #';

                                      }

                                      count++;

                                    }

                              }

                              if(manFields == ''){

                                      gsftSubmit(rec);

                              }

                              else{

                                      alert('The following fields must be completed: ' + manFields);

                                      return false;

                              }

                      }

              </script>                          

1 ACCEPTED SOLUTION

You have to remember that g:evaluate is done on the server, client scripts are done on the client and the Jelly stuff is all pre-processed first. Declaring a server variable cannot magically be used in a client script.



Try this:



if(art == ''){


                                      if(count > 0){


                                              manFields += ', '+='${artemis}';


                                      }


                                      else{


                                              manFields += ' '+='${artemis}';


                                      }


                                      count++;


                                    }


                              }



FWIW1: Whenever I see an if/else just to place a comma, my first instinct is to try and push all that information in to an array and then use join() to put the array in to a comma separated string. Far less code and keeping track of count variables to know if a comma is needed.



FWIW2: You might want to have a look at episodes 1-3 on all this stuff.


TechNow Episode List


View solution in original post

14 REPLIES 14

You set it in phase 1, but tried using it in phase 2.



Change $[ManFieldMsg] to ${ManFieldMsg}


Hmm... trying that and still getting same result with the following code:



<g:evaluate var="ManFieldMsg">


  gs.getMessage('ManFieldMsg');


  </g:evaluate>


              <script>



                      function checkMandatorySubmit(rec){


                              var storeUser = $[jvar_store_user];


                              if(storeUser)


                                      gsftSubmit(rec);


                              var manFields = '';


                              var pcnum = $[jvar_pcnum];


                              var approver = $[jvar_approver];


                              var store = $[jvar_store];


                              var secapprover = $[jvar_approver2];


                              var location = gel('location').value;


                              var cube = gel('cube_number').value;


                              var proj = gel('project').value;


                              var art = gel('artemis_number').value;


                              var count = 0;


                              if(location == ''){


                                      if(count > 0){


                                              manFields += ', Office Location';


                                      }


                                      else{


                                              manFields += 'Office Location';


                                      }


                                      count++;


                              }


                              if(pcnum == true){


                                      var pc = gel('pc_tag_num').value;


                                      if(pc == ''){


                                              if(count > 0){


                                                      manFields += ', PC Tag #';


                                              }


                                              else{


                                                      manFields += 'PC Tag #';


                                              }


                                              count++;


                                      }


                              }


                              if(approver == true){


                                      var app = gel('approver').value;


                                      if(app == ''){


                                              if(count > 0){


                                                      manFields += ', Approver';


                                              }


                                              else{


                                                      manFields += 'Approver';


                                              }


                                              count++;


                                      }


                              }


                              if(store == true){


                                      var str = gel('store').value;


                                      if(str == ''){


                                              if(count > 0){


                                                      manFields += ', Store';


                                              }


                                              else{


                                                      manFields += 'Store';


                                              }


                                              count++;


                                      }


                              }


                              if(secapprover == true){


                                      var app2 = gel('approver2').value;


                                      if(app2 == ''){


                                              if(count > 0){


                                                      manFields += ', Second Approver';


                                              }


                                              else{


                                                      manFields += 'Second Approver';


                                              }


                                              count++;


                                      }


                              }


                              if(proj == 'yes') {


                                  if(art == ''){


                                      if(count > 0){


                                              manFields += ', Artemis #';


                                      }


                                      else{


                                              manFields += 'Artemis #';


                                      }


                                      count++;


                                    }


                              }


                              if(manFields == ''){


                                      gsftSubmit(rec);


                              }


                              else{


                                      alert('${ManFieldMsg}' + manFields);


                                      return false;


                              }


                      }


              </script>                          



Message def exists and the message just won't display:



find_real_file.png



find_real_file.png



Also tried g2 on the evaluate and didn't work either.


Have you tried displaying the value of that variable right after your client script tag as a debug means?



<script>


alert('${ManFieldMsg}');


I did and the alert displays nothing


I don't believe the script tag understands the jelly="true" attribute. It's not necessary. Have you tried accessing it as a Javascript variable?



<g:evaluate>


  var ManFieldMsg = gs.getMessage('ManFieldMsg');


  </g:evaluate>


              <script>


                  alert('${ManFieldMsg}');