Our vBulletin migration is complete.
Welcome vBulletin users! All content and user information from the Micro Focus Forums (vBulletin) site has been migrated to this site. READ MORE.
Highlighted
iamManu Absent Member.
Absent Member.
736 views

Not able to put a value into a xml tag in the response using Scripted Javascript Rule

Jump to solution

Hi,

I am not able to put a value into a xml tag in the response using Scripted Javascript Rule. I am getting a value from another service using service call activity and trying to put the same in one of the tags of Virtual Service response. But getting "Internal server error TypeError: Cannot read property of undefined". 

Please find the attachment for the screenshot and help me if anyone knows the solution for this.

Thanks,

Manu

0 Likes
1 Solution

Accepted Solutions
iamManu Absent Member.
Absent Member.

Re: <<Subject change>> Not able to get a value from response of SCA using Scripted Javas

Jump to solution

Thanks Javo. It worked 🙂

0 Likes
4 Replies
javo Absent Member.
Absent Member.

Re: Not able to put a value into a xml tag in the response using Scripted Javascript Rule

Jump to solution

The response of Service Call Activity is supposed to be filled by response of remote service, so once SCA is called, it might overwrite data you are trying to write in scripted rule.

If you want to go this route anyway, then you need to create SCA response structure first in order to write something there. Now the script is complaining you are trying to access property on object, that is null. So you need to do something like this:

hpsv.serviceCallActivities[0].response.root = new Object();

hpsv.serviceCallActivities[0].response.root.ProcessData = new Object();

hpsv.serviceCallActivities[0].response.root.ProcessData.payload = "your value";
0 Likes
iamManu Absent Member.
Absent Member.

<<Subject change>> Not able to get a value from response of SCA using Scripted Javascript Rule

Jump to solution

Hi Javo, thanks for the reply.. I missed to specify that i am not able to get the value from a xml tag of SCA response. The response shown in the attached file is for the first line of code.. 

0 Likes
javo Absent Member.
Absent Member.

Re: <<Subject change>> Not able to get a value from response of SCA using Scripted Javas

Jump to solution

Maybe it is because SCA was not executed yet. You should put some condition on the presence of SCA response data like this:

if (hpsv.serviceCallActivities[0].response.root != null) {

// work with SCA result here as it was already populated

}

The above check is the safest way, but you might be able to avoid it if you postpone scripted rule execution. Right click on the rule, select Properties and check "Skip the first simulation pass".

BTW all values in the request/response objects are strings, so you don't need to convert it to string yourself.

0 Likes
iamManu Absent Member.
Absent Member.

Re: <<Subject change>> Not able to get a value from response of SCA using Scripted Javas

Jump to solution

Thanks Javo. It worked 🙂

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.