locked
Pop-up Reminders RRS feed

  • Question

  • I have severally pop-ups reminders that notify the users of the field that have no data. The field are so many that need the attention of the user. I want to Consolidate these Reminders Into One Message Box, after the form had finish loading, not to click for each and every reminder.
    Tuesday, August 10, 2010 10:22 AM

Answers

  • Hi,

    My suggestion would be to added CaseHasProblem, ProblemIsUnknown etc as fields on the form as you have ability to hide them. Onload check the related records and populate these fields. Then give a consolidated alert to the user.

    Regards

    Faisal

    • Marked as answer by Vicy1 Tuesday, August 10, 2010 1:32 PM
    Tuesday, August 10, 2010 12:18 PM
  • Hi,

    I have modified the code to just show one alert for all the conditions this should be much neater......

    if (crmForm.FormType == 2) { 
      var workImpact = crmForm.all.new_workimpact.DataValue;
      var alertMessage = null;
      
      if (workImpact == null) {
        alertMessage += "Reminder: WORK IMPACT for this case has not been set. Please set it as soon as the required information is available.\r\n"; 
       }
      else if (workImpact == "1") {
        alertMessage += "Reminder: WORK IMPACT for this case has not been assesed.\r\n"; 
      }
    
      if(window.CheckIfCaseHasProblems(crmForm.ObjectId) == false) {
        alertMessage += "There are no PROBLEMS currently associated to this case. A case should have at least one problem.\r\n"; 
      }
      else { 
        if (window.CheckIfProblemIsUknown(crmForm.ObjectId) == true) {
          alertMessage += "The PROBLEM currently associated to this case is UNKNOWN. Please update the case with the actual problem once it is known.\r\n";
        } 
      }
    
      if (CheckProblemNotes(crmForm.ObjectId) == true) {
        alertMessage += "The Problem Note currently associated to this case is not added. Please update the case with the problem.\r\n";
      }
    
      // if alert has any message
      if (alertMessage.length > 0) {
        alert(alertMessage);
      }
    }

    Hope this helps.. also suggest that you use Switch..case statement where you have more than 2 IF Else statements.

    Amar

    • Proposed as answer by Faisal Fiaz Tuesday, August 10, 2010 2:52 PM
    • Marked as answer by Vicy1 Wednesday, August 11, 2010 7:09 AM
    Tuesday, August 10, 2010 1:52 PM

All replies

  • Try to concatenate all message into one string:

    var message = "message1";

    message += "\r\n" + "message2";

    message += "\r\n" + "message3";

     

    alert(message);


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Tuesday, August 10, 2010 10:49 AM
    Moderator
  • Thanks andriy for the reply,

    I am very new on CRM 4.0 & JavaScript. I need it to execute first then must give me the result of the fields not assesed the portion of the reminders is as follows:

    if

     

     

    (crmForm.FormType == 2) {

     

     

    var workImpact = crmForm.all.new_workimpact.DataValue;

     

     

    if (workImpact == null) {

    alert("Reminder: WORK IMPACT for this case has not been set. Please set it as soon as the required information is available.");

     

    }

     

    else

     

     

    if (workImpact == "1") {

    alert(

     

    "Reminder: WORK IMPACT for this case has not been assesed.");

    }

    if

     

     

    (window.CheckIfCaseHasProblems(crmForm.ObjectId) == false) {

    alert(

     

    "There are no PROBLEMS currently associated to this case. A case should have at least one problem.");

    }

     

     

    else {

     

     

    if (window.CheckIfProblemIsUknown(crmForm.ObjectId) == true) {

    alert(

     

    "The PROBLEM currently associated to this case is UNKNOWN. Please update the case with the actual problem once it is known.");

    }

    }

     

     

    if (CheckProblemNotes(crmForm.ObjectId) == true) {

    alert(

     

    "The Problem Note currently associated to this case is not added. Please update the case with the problem.");

    }

    }

    Tuesday, August 10, 2010 11:41 AM
  • Hi,

    My suggestion would be to added CaseHasProblem, ProblemIsUnknown etc as fields on the form as you have ability to hide them. Onload check the related records and populate these fields. Then give a consolidated alert to the user.

    Regards

    Faisal

    • Marked as answer by Vicy1 Tuesday, August 10, 2010 1:32 PM
    Tuesday, August 10, 2010 12:18 PM
  • Thank you Faisal it worked, though I have only one error. After concanited all my alerts it also return those which should not return an value. it return them as "undefined".

    Can you also help about hiding the undifined message'

    Victoria

    Tuesday, August 10, 2010 1:44 PM
  • Before concatenation try to check if value is "undefined" don't concate it.
    Mahain : http://mahenderpal.wordpress.com
    Tuesday, August 10, 2010 1:48 PM
    Moderator
  • Hi,

    I have modified the code to just show one alert for all the conditions this should be much neater......

    if (crmForm.FormType == 2) { 
      var workImpact = crmForm.all.new_workimpact.DataValue;
      var alertMessage = null;
      
      if (workImpact == null) {
        alertMessage += "Reminder: WORK IMPACT for this case has not been set. Please set it as soon as the required information is available.\r\n"; 
       }
      else if (workImpact == "1") {
        alertMessage += "Reminder: WORK IMPACT for this case has not been assesed.\r\n"; 
      }
    
      if(window.CheckIfCaseHasProblems(crmForm.ObjectId) == false) {
        alertMessage += "There are no PROBLEMS currently associated to this case. A case should have at least one problem.\r\n"; 
      }
      else { 
        if (window.CheckIfProblemIsUknown(crmForm.ObjectId) == true) {
          alertMessage += "The PROBLEM currently associated to this case is UNKNOWN. Please update the case with the actual problem once it is known.\r\n";
        } 
      }
    
      if (CheckProblemNotes(crmForm.ObjectId) == true) {
        alertMessage += "The Problem Note currently associated to this case is not added. Please update the case with the problem.\r\n";
      }
    
      // if alert has any message
      if (alertMessage.length > 0) {
        alert(alertMessage);
      }
    }

    Hope this helps.. also suggest that you use Switch..case statement where you have more than 2 IF Else statements.

    Amar

    • Proposed as answer by Faisal Fiaz Tuesday, August 10, 2010 2:52 PM
    • Marked as answer by Vicy1 Wednesday, August 11, 2010 7:09 AM
    Tuesday, August 10, 2010 1:52 PM
  • Thank you all of you who replied this worked for and made my code very clean and readable.

    I have one more problem on function on the Code Block is on the onLoad

      // confirmation of the Customer change
      crmForm.all.customerid.onclick = function () {
        if (confirm("You are about to change the CUSTOMER on this case.")) {
          var lookupitem = new Array;
    
          lookupitem = crmForm.all.customerid.DataValue;
          var url = "/" + ORG_UNIQUE_NAME + "/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=1&browse=0&ShowNewButton=0&ShowPropButton=1&DefaultType=0";
          var args = null;
          var style = "dialogHeight:30;dialogWidth:40;center:yes;resizable:yes";
          var result = window.showModalDialog(url, args, style);
          var lookupItems = new Array()
          var lookupItem = new Object();
    
          if (result != null) {
            lookupItem.id = result.items[0].id;
            lookupItem.name = result.items[0].name;
            lookupItem.type = result.items[0].type;
            lookupItem.typename = "account";
            lookupItems[0] = lookupItem;
    
            lookupitem = crmForm.all.customerid.DataValue = lookupItems;
          }
          else {
    
            lookupitem = crmForm.all.customerid.DataValue = null;
          }
        }
      }
    This is on the onChanged event of my Customer Lookup field, when I click a Customer lookup and select the companies in a lookup the Site
    should clean the existing site and Contract lookup field should automaticaly add the relevent contract and disabled a lookup.
    This code worked for few days and never worked again. can you help me with this too.
    // Clearing the Site field
    crmForm.all.contractid.DataValue = null;
    crmForm.all.new_siteid.DataValue = null;
    crmForm.all.contractid.ForceSubmit = true;
    
    var customer = crmForm.all.customerid.DataValue;
    if (customer != null) {
      //retrieve active contracts linked to the selected customer 
      var activeContract = window.RetrieveActiveContract(customer[0].id);
      if (activeContract != null) {
        //Create an array to set as the DataValue for the lookup control.
        var lookupData = new Array();
        //Create an Object add to the array.
        var lookupItem = new Object();
        //Set the id, typename, and name properties to the object.
        lookupItem.id = activeContract.id;
        lookupItem.typename = 'contract';
        lookupItem.name = activeContract.name;
        // Add the object to the array.
        lookupData[0] = lookupItem;
        // Set the value of the lookup field to the value of the array.
        crmForm.all.contractid.DataValue = lookupData;
      }
    
    }

    Thank you to you all

    Victoria

    Wednesday, August 11, 2010 7:30 AM
  • Hi

    Your code looks good move the below line to OnSave but was not sure about "window.RetrieveActiveContract(customer[0].id);". Are you able to set the value of contractid once the above function returns a value?

    crmForm.all.contractid.ForceSubmit = true;

    To disable the field you can use

    crmForm.all.<crm attribute namr>.disabled = true;

    and ..to enable use

    crmForm.all.<crm attribute namr>.disabled = false;

    Thanks,

    Amar

    • Proposed as answer by Faisal Fiaz Wednesday, August 11, 2010 10:08 AM
    Wednesday, August 11, 2010 9:18 AM
  • I have changed my onClick event to attachedEvent it does clear and load the relevent contract but does not give the confirmation message first if I click the lookup.

    It is working fine the only problem is that it has to give me first that confirmation before I select the Customer

    I changed the code to the following.

    If I debugger it it does see the confirmation message but when I run it on the client side it does not pop up the confirmation message.

    What is it that I am doing wrong.

    // confirmation of the Customer change
        crmForm.all.customerid.attachEvent = function () {
          if (confirm("You are about to change the CUSTOMER on this case.")) {
          var lookupitem = new Array;
    
          lookupitem = crmForm.all.customerid.DataValue;
          var url = "/" + ORG_UNIQUE_NAME + "/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=1&browse=0&ShowNewButton=0&ShowPropButton=1&DefaultType=0";
          var args = null;
          var style = "dialogHeight:30;dialogWidth:40;center:yes;resizable:yes";
          var result = window.showModalDialog(url, args, style);
          var lookupItems = new Array()
          var lookupItem = new Object();
    
          if (result != null) {
            lookupItem.id = result.items[0].id;
            lookupItem.name = result.items[0].name;
            lookupItem.type = result.items[0].type;
            lookupItem.typename = "account";
            lookupItems[0] = lookupItem;
    
            lookupitem = crmForm.all.customerid.DataValue = lookupItems;
         
            crmForm.all.customerid.attachEvent("onclick", alert("You are about to change the CUSTOMER on this case."));
          }
          else {
    
            lookupitem = crmForm.all.customerid.DataValue = null;
          }
        }
      }
    Then on the onChange event of my Customer lookup I haven't changed any thing.
    crmForm.all.contractid.DataValue = null;
    crmForm.all.new_siteid.DataValue = null;
    crmForm.all.contractid.ForceSubmit = true;
    
    var customer = crmForm.all.customerid.DataValue;
    if (customer != null) {
     //retrieve active contracts linked to the selected customer 
     var activeContract = window.RetrieveActiveContract(customer[0].id);
     if (activeContract != null) {
      //Create an array to set as the DataValue for the lookup control.
      var lookupData = new Array();
      //Create an Object add to the array.
      var lookupItem = new Object();
      //Set the id, typename, and name properties to the object.
      lookupItem.id = activeContract.id;
      lookupItem.typename = 'contract';
      lookupItem.name = activeContract.name;
      // Add the object to the array.
      lookupData[0] = lookupItem;
      // Set the value of the lookup field to the value of the array.
      crmForm.all.contractid.DataValue = lookupData;
     }
    
    }
    Wednesday, August 11, 2010 10:51 AM