Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

help on javascript for CRM Action

Posted on by 1,695

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

  • Pete_N Profile Picture
    Pete_N 1,695 on at
    RE: help on javascript for CRM Action

    A big thank you for all your help

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: help on javascript for CRM Action

    Try following:

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


  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: help on javascript for CRM Action

    Hi ,

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

  • Pete_N Profile Picture
    Pete_N 1,695 on at
    RE: help on javascript for CRM Action

    HI,

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

    Java-2.jpg

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: help on javascript for CRM Action

    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
    Pete_N 1,695 on at
    RE: help on javascript for CRM Action

    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
    gdas 50,085 on at
    RE: help on javascript for CRM Action

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


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

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans