-1

What i am trying to achive is values are sent to via REST message, i am trying to place these values in a JSON format, so they can be placed into a field on a form.

var membersToAddArry = [];
membersToAddArry = request.queryParams.MembersToAdd.toString().split(";");    

   for(var x = 0; x < membersToAddArry.length-1; x++)
    {
        dn = membersToAddArry[x].toString();
        userJSONAdd["DistinguishedName"] = dn;
        userJSONAddn[x] = userJSONAdd;
    }
    return userJSONAddn;

Data sent:

CN=smcgh,OU=Lost-Found,OU=Corp,DC=test,DC=COMPANY,DC=com;

CN=syouz,OU=Lost-Found,OU=Corp,DC=test,DC=COMPANY,DC=com;

This returns:

    {
  "result": {
    "0": {
      "DistinguishedName": "CN=syouz,OU=Lost-Found,OU=Corp,DC=test,DC=COMPANY,DC=com"
    },
    "1": {
      "DistinguishedName": "CN=syouz,OU=Lost-Found,OU=Corp,DC=test,DC=COMPANY,DC=com"
    }
  }
}

The two bits of information are repeating how can i stop this?

8
  • 1
    Are you sure you want to split at semicolons and not at commas? Commented Dec 6, 2016 at 11:23
  • The last entry in the array is "", and you're overwriting userJSONAdd in each loop, so only the last element remains, which happens to be an empty string… Commented Dec 6, 2016 at 11:24
  • @KamenMinkov I need the full Distinguished name sadly Commented Dec 6, 2016 at 11:27
  • @deceze i changed my length to length -1 still did not fix the issue Commented Dec 6, 2016 at 11:28
  • Check your array membersToAddArry to remove duplicates elements Commented Dec 6, 2016 at 13:44

1 Answer 1

1

Reinit your object userJSONAdd in the for-loop. Otherwise you add two times the same object but you change the value of the field DistinguishedName so you gets two times the same value :

var membersToAddArry = [];
membersToAddArry = request.queryParams.MembersToAdd.split(";");    

for(var x = 0; x < membersToAddArry.length-1; x++)
{
    userJSONAdd = {};
    dn = membersToAddArry[x].toString();
    userJSONAdd["DistinguishedName"] = dn;
    userJSONAddn[x] = userJSONAdd;
}
return userJSONAddn;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.