Pass the script include output in client script

Rakshanda Kunte
Tera Contributor

Hi All,

 

I have script include Output as below:

- return ID+ GroupName;

i.e. 12345abcd6789Hardware

 

Now, I need to use both the outputs i.e., ID and group name in client script. 

Here, group name can be anything, so how can I show that in client script?

 

Requirement: How can I split the output from script include? as I want to use ID in if statement and group name in error message.

 

Client script:

 

function scriptinclude (response) {
        var a = response.responseXML.documentElement.getAttribute("answer");
        g_form.addInfoMessage(a);                                        // [12345abcd6789Hardware] - this is output here
        if (a == '12345abcd6789' ) {
            g_form.addErrorMessage('GroupName already exist with this id');            //Groupname will be groupname obtained from output of script include 
        }
        else if (a == '10111213tyu1415')
{
g_form.addErrorMessage('GroupName already exist with this id');        //Groupname will be groupname obtained from output of script include 
        }

 

1 ACCEPTED SOLUTION

Prince Arora
Tera Sage
Tera Sage

@Rakshanda Kunte 

 

Hi could you please try below;

 

return (ID+ ":" +GroupName).toString();

 

 

function scriptinclude (response) {
 var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.split(":");
g_form.addInfoMessage(answer[0]);
g_form.addInfoMessage(answer[1]);
 if (answer[1] == 'abcd6789' ) {
 g_form.addErrorMessage('GroupName already exist with this id');            //Groupname will be groupname obtained from output of script include 
  }  else if (answer[1] == 'tyu1415'){
g_form.addErrorMessage('GroupName already exist with this id');        //Groupname will be groupname obtained from output of script include 
 }
}

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

View solution in original post

8 REPLIES 8

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Rakshanda Kunte ,

 

Instead of passing values this way, you can pass a JSON object which would contain the ID and group name separately and then you can fetch them in the client script, please refer to the scripts below:

Script include:

 

 

var obj = {};
obj.id = ID; 
obj.group_name = GroupName;
return JSON.stringify(obj);

 

 

 

Client script:

 

 

function scriptinclude (response) {
 var a = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
alert(a.id + ' ' + a.group_name);
 if (a.group_name == 'abcd6789' ) {
 g_form.addErrorMessage('GroupName already exist with this id');            //Groupname will be groupname obtained from output of script include 
  }  else if (a.group_name == 'tyu1415'){
g_form.addErrorMessage('GroupName already exist with this id');        //Groupname will be groupname obtained from output of script include 
 }
}

 

 

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

@Karan Chhabra6 ,

Thanks for looking into this. 

 

g_form.addInfoMessage(a.ID);

g_form.addInfoMessage(a.group_name);

 

However, these 2 lines are not giving any output. 

@Karan Chhabra6 ,

 

If I only return a in client script,

i.e. g_form.addInfoMessage(a);

 

Output =  {"id":"123456ty56vce6","group_name":"Hardware"}

@Rakshanda Kunte  - if you're using this for testing, you can use alert() insert, I've updated the code, please refer that.

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!