Search code examples
javascriptwhitespacepaddingmicrosoft-dynamicsdynamics-365

Javascript padStart() working correctly in alert box but not in email record in Dynamics 365 CRM


I have created an action that gets values from a CRM record in which are appended in a stringbuilder. Within the string that is being built, I need to add something to the equivalent of 10 spaces between the string as seen below:

for(var i = 0; i < ltRecordSnsAndLocations.length; i++)
{
    if(i < ltRecordSnsAndLocations.length - 1)
    {
        injectionString += (i+1).toString() + ". " + ltRecordSnsAndLocations[i][0].toString() + String("System Location:  ").padStart(String("System Location:  ").length+10,' ') + ltRecordSnsAndLocations[i][1].toString() + "\n";
    }

Which seems to be working correctly seen by the output in the alert box below:

enter image description here

As you can see, there is the correct padding between the number bulletted values and the system location which is what I want.

As stated earlier, I created an action in CRM which inputs this string into an email record denoted by the variable injectionString as seen below:

enter image description here

However, when the workflow kicks off and the injectionString passed in is populated, it ignores the padStart as seen below:

enter image description here

I've been fighting with this for a while now. Important to note that I tested in both Chrome and Edge Browsers. Any help on this is much appreciated.


Solution

  • The following blogpost provided the solution to my problem:
    https://blog.hubspot.com/website/html-space

    The simplest way to add a space in HTML (besides hitting the spacebar) is with the non-breaking space entity, written as &nbsp; or &#160;. Multiple adjacent non-breaking spaces won’t be collapsed by the browser, letting you “force” several visible spaces between words or other page elements.

    enter image description here