CRM2016 on premises
I have the following Javascript which i am trying to develop to pass a result to a parameter in an action. I haven't included the callbacks yet, just stuck on one issue. I need to put the selected ID's into a string, but after hours of playing I'm till no further forward.
Im looking to get a string called stringlist = selecteditemid ( array 0 ) +"," + selecteditemid (array 1 ) + "," selecteditemid (array 3 ) ect but with no "," after the last item in the array
function BuildBACSFile(selectedItems)
{
for (var i = 0; i < selectedItems.length; i++)
{
var selectedItem = selectedItems[i];
alert("Id=" + selectedItem.Id );
}
}
*This post is locked for comments
A big thank you for all your help
Try following:
function BuildBACSFile(selectedItems){ var stringlist =""; for (var i = 0; i < selectedItems.length; i++){ stringlist += (stringList == "" ? "" : ",") + selectedItems[i].Id; } alert(stringList); }
Hi ,
probably this could be the reason instead or selectedItems[i].id it will be selectedItems[i].Id
HI,
Again thank you for your assistance. The alert is not giving me the ID's. all im getting out is
Hi,
Try with this -
function BuildBACSFile(selectedItems) { var stringlist =""; for (var i = 0; i < selectedItems.length; i++) { if(stringlist != "") { if(selectedItems[i] != null && selectedItems[i] != undefined) stringlist = stringlist + "," + selectedItems[i].id; } else { if(selectedItems[i] != null && selectedItems[i] != undefined) stringlist = selectedItems[i].id; } } alert("stringlist= " + stringlist ); }
Hi,
Thank you for your help, it has gone a long way although not quite the result I need.
This javascript will is being fired from a button on a view and its the selected items Id's of the selected rows I need to get
I added an alert to see what stringlist was producing and its showing [object Object] where I need the stringlist to contain the selecteditems.id
I have tried
function BuildBACSFile(selectedItems)
{
var stringlist ="";
for (var i = 0; i < selectedItems.length; i++)
{
if(stringlist != "")
{
if(selectedItems[i] != null && selectedItems[i] != undefined)
var selectedItem = selectedItems[i];
stringlist = stringlist + "," + selectedItem.id;
}
else
{
var selectedItem = selectedItems[i];
stringlist = selectedItem.id;
}
}
alert("stringlist= " + stringlist );
}
but all I get is stringlist = undefined
Hi ,
Try with this -
function BuildBACSFile(selectedItems) { var stringlist =""; for (var i = 0; i < selectedItems.length; i++) { if(stringlist != "") { if(selectedItems[i] != null && selectedItems[i] != undefined) stringlist = stringlist + "," + selectedItems[i]; } else { stringlist = selectedItems[i]; } } }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156