web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

help on javascript for CRM Action

(0) ShareShare
ReportReport
Posted on by 1,703

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

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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];
                }             
            }  
        }


  • Pete_N Profile Picture
    1,703 on at

    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

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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 );
    }

  • Pete_N Profile Picture
    1,703 on at

    HI,

    Again thank you for your assistance. The alert is not giving me the ID's. all im getting out is

    Java-2.jpg

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    probably this could be the reason instead or selectedItems[i].id  it will be selectedItems[i].Id

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try following:

    function BuildBACSFile(selectedItems){
           var stringlist ="";
           for (var i = 0; i < selectedItems.length; i++){
    		stringlist += (stringList == "" ? "" : ",") + selectedItems[i].Id;
           }
    
    	alert(stringList);
    }


  • Pete_N Profile Picture
    1,703 on at

    A big thank you for all your help

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Shidin Haridas Profile Picture

Shidin Haridas 2

#2
Abdullah13 Profile Picture

Abdullah13 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans