Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Build Array from service data

Hi,
Could you give me some pointers with the following.

I have a service that returns details of current jobs for the logged on user, I want to call the service with variables added from local storage, two variables are required I am not quite sure how you would construct the two variables to pass as a single variable to the service:
var delimiterA = localStorage.getItem(account);
var delimiterB = localStorage.getItem(user);

var job = new Array();
job = jobsservice.execute({delimeter});

at this point I want to extract an element (jobnumber) from each job that is returned checkout local storage to see if the job already exists and if not add the job as an stringified array.

I have not quite got this can you show me the correct methods required to achieve the building of the delimiter and how to save the returned jobs as a query able array at the moment my var job is returned as an object. The data returned from the service using the test button is below.

[
{
"id":"50bcba40e4b0747d4efe4db5",
"createdAt":"2012-12-03 06:42:08.533",
"updatedAt":"2012-12-13 08:38:59.871",
"account":"systems",
"address":"Ford Genk,
Mondeo Street,
Genk,
Belgium",
"contact":"j.bohen",
"driver":"joe",
"duedate":"2012-12-07 20:00:00.000",
"goodsdescription":"12 euro pallets",
"jobnum":"100123:del1",
"latlon":"45.344512,
-1.27667",
"status":"On Route"
},
{
"id":"50bcb898e4b0747d4efe4db4",
"createdAt":"2012-12-03 06:35:04.545",
"updatedAt":"2012-12-13 08:39:22.567",
"account":"systems",
"address":"Ford Motors,
Hall Lane Ind Est,
Melton Mowbray,
Leicestershire",
"contact":"j.bohen",
"driver":"joe",
"duedate":"2012-12-05 06:00:00.000",
"goodsdescription":"12 euro pallets",
"jobnum":"100123:col2",
"latlon":"45.344512,
-1.27667",
"status":"On Site"
}
]

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Build Array from service data

It's not clear what format you need, but to add two variables:

var result = delimiterA + delimiterB;

http://www.quirksmode.org/js/strings....

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Build Array from service data

Hi Max,

Thanks for your reply which sorts out the construction of the delimiter. What I wish to achieve is the saving of the service results as a Json string to a local storage variable,

If I do this it obviously wont work but It might explain what I am trying to achieve. I am building the two variables from two local storage variables then attempting to pass these into the service request. I want to save the results to another local storage variable.

var driv = '{"jobnum":"'+ localStorage.getItem('driver') +'"}';
var acc = '{"account":"'+ localStorage.getItem('user') +'"}';
var job = new Array();
job = jobsservice.execute({driv + ',' + acc});

localStorage.setItem(jobnum, job);

Regards,
Joe

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Build Array from service data

Hello!

"I am building the two variables from two local storage variables then attempting to pass these into the service request."

You can achieve this using mapping.

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Build Array from service data

Hi Marina,

I want to save the resulting records as a JSON.stringify string into local storage, how do I achieve this using mapping?

Regards,
Joe

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Build Array from service data

You can add JS here

Image

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Build Array from service data

Thanks but how do I get a handle to the returned data so that it can be saved to local storage.

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Build Array from service data

Can you show me an example please.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Build Array from service data

There is no way to do it using mapping only...

But here is a solution - save array into localStorage

Add Succes event for your RestService and action Run Custom JS

localStorage.setItem('resultArray', JSON.stringify(data));

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Build Array from service data

Hi Marina,

Thanks for that I will try it out.

Regards,
Joe

Return to “Issues”