locked
onload event by owner to change default of picklist RRS feed

  • Question

  • hello everybody,

    I have an issue. I tried to accomplish this with a workflow, but it hasn't seemed to work. My goal is to have a pick list that has three values (Department 1, Department 2, Both) to be selected by who owns the account. I have the default as Department 1 because that is the only department now, using the CRM right now, but the other one will be joining shortly. is there an onload script that can choose a picklist value depending on the owner? the workflow I tried was check condition (if the owner is...) then update record (set department as...) i selected the on record creation and it was set as child workflow and on demand. i am using Dynamics 4.0. any help would be very much appreciated

    Friday, February 25, 2011 4:35 PM

Answers

  • 1. Change Picklist name according to your envoirnment.

    2. Change Picklist Value according to your envoirnment.

     I have made things easier by using user name instead of id. Put this code onload event and publish customization:-

    var xml = "" + 
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
    GenerateAuthenticationHeader() +
    " <soap:Body>" + 
    " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    " <q1:EntityName>systemuser</q1:EntityName>" + 
    " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    " <q1:Attributes>" + 
    " <q1:Attribute>businessunitid</q1:Attribute>" + 
    " <q1:Attribute>fullname</q1:Attribute>" + 
    " <q1:Attribute>systemuserid</q1:Attribute>" + 
    " </q1:Attributes>" + 
    " </q1:ColumnSet>" + 
    " <q1:Distinct>false</q1:Distinct>" + 
    " <q1:Criteria>" + 
    " <q1:FilterOperator>And</q1:FilterOperator>" + 
    " <q1:Conditions>" + 
    " <q1:Condition>" + 
    " <q1:AttributeName>systemuserid</q1:AttributeName>" + 
    " <q1:Operator>EqualUserId</q1:Operator>" + 
    " </q1:Condition>" + 
    " </q1:Conditions>" + 
    " </q1:Criteria>" + 
    " </query>" + 
    " </RetrieveMultiple>" + 
    " </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
    
    var fullNameNode = entityNode.selectSingleNode("q1:fullname");
    var fullname = (fullNameNode == null) ? null : fullNameNode.text; 
    
    alert(fullname);
    
    var Picklist=crmForm.all.accountcategorycode; // Change Picklist Schema name here
    
    if (fullname == 'CRM Admin')
    {
     Picklist.DeleteOption( 200000); //remove option with value 200000
     }
    else if (fullname == 'Faisal Fiaz')
    {
     Picklist.DeleteOption( 200004); //remove option with value 200004
     }
    
    

    Regards Faisal
    Tuesday, March 1, 2011 10:59 AM

All replies

  • If you use business unit than it would be easy however it is also possible with the user:-

    http://mahenderpal.wordpress.com/2010/08/30/remove-picklist-option-based-on-security-roles/


    Regards Faisal

    Friday, February 25, 2011 4:50 PM
  • Create a Picklist in system user with values Department1,  Department2, Both and use the ajax query to retrieve the owner information in Onload and set the value for picklist.

     

    Regards Vinoth.

    • Proposed as answer by Vnothkumar Saturday, February 26, 2011 2:52 AM
    Saturday, February 26, 2011 2:52 AM
  • how would i go about doing that?
    Monday, February 28, 2011 6:45 PM
  • hi Jacob

     

    1) Create a Picklist in SystemUser as Department with Values Department1, Department2, Both.

    2)Create the same picklist in entity you want  Display

     

    var userId = crmForm.all.ownerid.DataValue[0].id;
    var authenticationHeader = GenerateAuthenticationHeader();
    
    // Prepare the SOAP message.
    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    <soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    authenticationHeader +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>systemuser</entityName>" +
    "<id>" + userId + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" + "<q1:Attributes>" + "<q1:Attribute>new_department</q1:Attribute>" + "</q1:Attributes>" + "</columnSet>" + "</Retrieve>" + "</soap:Body>" + "</soap:Envelope>"; // Prepare the xmlHttpObject and send the request. var xHReq = new ActiveXObject("Msxml2.XMLHTTP"); xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve"); xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xHReq.setRequestHeader("Content-Length", xml.length); xHReq.send(xml); var resultXml = xHReq.responseXML; var value = resultXml.selectSingleNode("//q1:new_department").nodeTypedValue; //To Set Department based on Owner crmForm.all.new_department.DataValue = value;

     

    note: Change the schema name as per your requirement. 

     

    Regards,

    Vinoth

    • Proposed as answer by Vnothkumar Tuesday, March 1, 2011 5:28 AM
    Tuesday, March 1, 2011 3:42 AM
  • 1. Change Picklist name according to your envoirnment.

    2. Change Picklist Value according to your envoirnment.

     I have made things easier by using user name instead of id. Put this code onload event and publish customization:-

    var xml = "" + 
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
    GenerateAuthenticationHeader() +
    " <soap:Body>" + 
    " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    " <q1:EntityName>systemuser</q1:EntityName>" + 
    " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    " <q1:Attributes>" + 
    " <q1:Attribute>businessunitid</q1:Attribute>" + 
    " <q1:Attribute>fullname</q1:Attribute>" + 
    " <q1:Attribute>systemuserid</q1:Attribute>" + 
    " </q1:Attributes>" + 
    " </q1:ColumnSet>" + 
    " <q1:Distinct>false</q1:Distinct>" + 
    " <q1:Criteria>" + 
    " <q1:FilterOperator>And</q1:FilterOperator>" + 
    " <q1:Conditions>" + 
    " <q1:Condition>" + 
    " <q1:AttributeName>systemuserid</q1:AttributeName>" + 
    " <q1:Operator>EqualUserId</q1:Operator>" + 
    " </q1:Condition>" + 
    " </q1:Conditions>" + 
    " </q1:Criteria>" + 
    " </query>" + 
    " </RetrieveMultiple>" + 
    " </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
    
    var fullNameNode = entityNode.selectSingleNode("q1:fullname");
    var fullname = (fullNameNode == null) ? null : fullNameNode.text; 
    
    alert(fullname);
    
    var Picklist=crmForm.all.accountcategorycode; // Change Picklist Schema name here
    
    if (fullname == 'CRM Admin')
    {
     Picklist.DeleteOption( 200000); //remove option with value 200000
     }
    else if (fullname == 'Faisal Fiaz')
    {
     Picklist.DeleteOption( 200004); //remove option with value 200004
     }
    
    

    Regards Faisal
    Tuesday, March 1, 2011 10:59 AM