Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Javascript show icon in view

Posted on by 600

Hi 

I am trying to show a icon in a subgrid/view with the following javascript, but it is not working?

function checkTest(rowData, userLCID) {
var str = JSON.parse(rowData);
var coldata = str.scheduledend_Value;
var imgName = "";
var tooltip = "";

if (coldata) {
var subjectText = Xrm.Page.getAttribute("subject").getValue();
var testdrive = subjectText.includes("testdrive");
var prøvekjøring = subjectText.includes("prøvekjøring");
if (prøvekjøring == true || testdrive == true) {
imgName = "mb_datePassed";
tooltip = "Forventet dato for signering er passert";
}

}
var resultarray = [imgName, tooltip];
return resultarray;
}

Any ideas what is wrong?

Thanks!

*This post is locked for comments

  • martingr Profile Picture
    martingr 600 on at
    RE: Javascript show icon in view

    Thank you.

    I think this script now works :-)

    function setTestDriveIcon(rowData, userLCID) {

         var str = JSON.parse(rowData);

         var coldata = str.scheduledend_Value;

         var imgName = "";

         var tooltip = "";

         var sub = str.subject;

         if (coldata) {

             var testdrive = sub.includes("testdrive");

             var prøvekjøring = sub.includes("prøvekjøring");

             if (prøvekjøring == true || testdrive == true) {

                 imgName = "mb_testdrive32x32.png";

                 tooltip = "Forventet dato for signering er passert";

             }

         }

         var resultarray = [imgName, tooltip];

         return resultarray;

     }

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript show icon in view

    Hi,

    It looks like coldata is of type date and you are checking it as bool i.e. if (coldata). Put some alert or debug it to check the value returned and change your code accordingly.

    If still doesn't work, share some more details about your entity, fields and data type.

    Hope this helps.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Javascript show icon in view

    Hi Martin,

    You can not get value of a field using Xrm method in the view . If you want to get the value , you need to be included in the view itself and try to get the value from coldata and then use case statement .

    For example :

     var str = JSON.parse(rowData);

       var sub = str.subject

    Try to hide the condition code , hope you will see the icon without condition . Try with below code. Make sure you are providing correct image url. For more information please have a look below reference -

    http://mscrmshop.blogspot.com/2016/12/adding-icons-and-tooltips-to-grid.html

      function checkTest(rowData, userLCID) {
          var str = JSON.parse(rowData);
          var coldata = str.scheduledend_Value;
          var imgName = "";
          var tooltip = "";
    
          if (coldata) {
              //var subjectText = Xrm.Page.getAttribute("subject").getValue();
              //var testdrive = subjectText.includes("testdrive");
              //var prøvekjøring = subjectText.includes("prøvekjøring");
              //if (prøvekjøring == true || testdrive == true) {
                  imgName = "mb_datePassed";
                  tooltip = "Forventet dato for signering er passert";
             // }
    
          }
          var resultarray = [imgName, tooltip];
          return resultarray;
      }


    Hope this helps .

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans