Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

JavaScript to Retrieve Field Values from Opportunity and Pass to Opportunity Close as Text Fields

$
0
0

We have a need in our process to pass information from three fields in the Opportunity record to the Opportunity Close form.  Two of these fields are Lookup fields to other custom entities while one is an option set.  This information was to passed through JavaScript but I am having issues pulling the text from the lookup fields and so must have something wrong.  (I'm a bit new to JavaScript).  I'm hoping someone might be able to help with this coding or perhaps there is a better way to pass this information over.  Below is a sample of the JavaScript.  Thanks.

functiongetRelatedInfo(e) {

    // Get the Form Context
    varformContext=e.getFormContext();

    // Set variables for the related entity to get data from
    try{varrecordGuid=formContext.getAttribute("opportunityid").getValue()[0].id; }
    catch(err) {}

    // If the recordGuid contains data
    if (recordGuid!=null) {
   
        // Use the WebApi to get data    
        Xrm.WebApi.retrieveRecord("opportunity", recordGuid, "?$select=z2t_optype&$expand=z2t_Division($select=z2t_name),z2t_Make($select=z2t_name)").then(
           
            // If successful, set variables for the results
            functionsuccess(result) {
                varOpType=result.z2t_optype;

                if (result.hasOwnProperty("z2t_Division") &&result["z2t_Division"] !==null) {
                    varDivision=result["z2t_Division"]["z2t_name"]; // Text
                }
                if (result.hasOwnProperty("z2t_Make") &&result["z2t_Make"] !==null) {
                    varMake=result["z2t_Make"]["z2t_name"]; // Text
                };
           
       

                // Set the form fields
                formContext.getAttribute("gp_opportunitytype").setValue(OpType);
                formContext.getAttribute("gp_Division").setValue(z2t_Division_z2t_name);
                formContext.getAttribute("gp_Make").setValue(z2t_Make_z2t_name);
       

            },                                                  
                       

Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images