Jerry7185911
Posts: 0
Joined: Thu Oct 23, 2014 9:18 pm

manipulate multiple mapping values via javascript

I have mapped two values from my database response to a single control. For example, firstname and lastname. I want to combine these using javascript in the mapping action editor:

function (value, element) {

return value.firstname + " " + value.lastname;

dot notation does not seem to work, and accessing value only returns the 2nd value that is mapped (lastname). Is there a way to do this?

thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

manipulate multiple mapping values via javascript

Hello Jerry,

value.firstname and value.lastname are not defined in the code where you add it. In value you will have the value of lastname or firstname, just strings. You should add this code in the mapping of the whole object and fill in result the desired element using js.
Please see this discussion https://getsatisfaction.com/apperyio/...

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

manipulate multiple mapping values via javascript

I'd respectfully add however knowing Evegene is extremely qualified ... That you could place a hidden control on the page, have the first and last names as hidden controls, and then in a post mapping event .... Select run JavaScript ...and then in that event: ( replace the control names below with yours )

var scombinedname ;
Scombinedname = Appery( 'controlnameforfirstname').val() + "." + Apppery('controlnameforlastname').val();
Appery('controlnameforfirstandlast'):val( scombinedname )

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

manipulate multiple mapping values via javascript

And perhaps you also might ned to re-show the control with

Appery('combinedcontrolname').show();

Jerry7185911
Posts: 0
Joined: Thu Oct 23, 2014 9:18 pm

manipulate multiple mapping values via javascript

thank you both for your help.

So i have played around with all these approaches - and had trouble using both controls and localstorage because i am mapping to a list item with multiple rows. I'm sure it could be done, but I was more interested in the explanation in the link provided regarding how multiple mappings are handled. Obviously, why have multiple mappings if only the last one is relevant? well, apparently all the mappings are passed as separate calls to the javascript in the order the mappings are added. So in my case, I was able to add firstname and lastname mappings to the same destination control - and I added this javascript:

var result = "";
if (element.text().trim().length === 0)
{
result = value;
}
else
{
result = element.text() + " at " + value;
}
return result;

For the first call, the control was always empty (though I had to use the trim() because it contained 29 spaces every time - not sure why. it may have been an artifact of having a default value and then removing it). Then the second time, it had content/length, so I could handle the value as the second mapping value.

Hopefully this helps others understand how to use multiple mappings - especially in a list item situation where controls and localstorage can get complicated.

thanks again!

Jerry7185911
Posts: 0
Joined: Thu Oct 23, 2014 9:18 pm

manipulate multiple mapping values via javascript

Bruce - I'm sure this would work perfectly with a single row result. thanks for the suggestion.

Return to “Issues”