Page 1 of 1

Setting pointer value when creating a record in a collection using the service mapper

Posted: Mon Dec 16, 2013 11:43 pm
by 2fas2c

I have Accounts collection and Cards collection. Cards collection has a pointer to Accounts called accountId. I went through a few tutorials and I was able to successfully execute the Create Rest Service on Cards with the AccountId pointer populated. I am trying to do the same using the mapping and I am unable to.

On the Add Card page, I have a select box for Accounts that I am populating on load with a key of AccountId and a value of AccountName. On the data tab, I have added the add service for Card, did the mappings on the request tab. I am not sure how/what I need to map to accountId from the page. I tried adding a javascript that does

return '{"collName":"Accounts", "_id": "' + value + '"}'

but that returns a string and accountId is expecting an object since it is a pointer to Accounts collection.

Image

I am sure I am missing something basic. Please help

Thanks
Image


Setting pointer value when creating a record in a collection using the service mapper

Posted: Tue Dec 17, 2013 12:47 am
by Alena Prykhodko

Hello!

Where do you run this JS code?


Setting pointer value when creating a record in a collection using the service mapper

Posted: Tue Dec 17, 2013 2:02 am
by 2fas2c

By clicking on addJS next to the accountId text box on request mapping page.

Thanks


Setting pointer value when creating a record in a collection using the service mapper

Posted: Tue Dec 17, 2013 9:05 am
by Maryna Brodina

Hello! Return object, not string prereturn {"collName":"Accounts", "_id": value };/pre


Setting pointer value when creating a record in a collection using the service mapper

Posted: Fri Dec 20, 2013 4:14 am
by 2fas2c

This worked. I am trying to query with a where clause and it fails. I have accountId stored in a local variable and I have the following code under "Add JS" of the where clause

return {"accountId":{"$inQuery":{"_id":value}}};

I get an error and it is complaining about where [object object]

Thanks


Setting pointer value when creating a record in a collection using the service mapper

Posted: Fri Dec 20, 2013 4:17 am
by 2fas2c

I figured it out. This should return a string since where clause is a string..

I changed the Javascript code to
return '{"accountId":{"$inQuery":{"_id":"' + value + '"}}}';

and it works.. Thanks


Setting pointer value when creating a record in a collection using the service mapper

Posted: Fri Dec 20, 2013 6:38 am
by Maryna Brodina

Hello! Thank you for update!