Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

i have created js script in dynamics 365 when we click on button on select of record it will create record in other table but im unable to copy status choice column and Roitext text column to another table column

(0) ShareShare
ReportReport
Posted on by 102

i have created js script in dynamics 365 when we click on button on select of record it will create record in other table

the table is creating and also im able to copy the primary column but im unable to copy sstatus choice column and Roitext text column to another table column

I have two tables "Pre Approval Header" and "Claim Header" , once record is created in Pre Approval Header table , i want to copy two fields Primary column and status choice column and Roitext text column to the Claim header table using JS script.

Image

When i click on "Claim Create" button i added using ribbon workbech, it will create new record in  Claim header

Image'

Image

In Claim header table, i was able to copy the Primary column "Pre approval Refrence"  to the Cliam header table, but status column is not copied.

want to know, how to copy status choice column and Roitext text column too, below is the code i used to copy Primary column " Pre approval refrence"

function enableclaimcreate(SelectedControl)
{
     var returnflag = true;
     return returnflag;
    
}

function onclickinitiateClaim(SelectedControl)
{
    var selectedRow = SelectedControl.getGrid().getSelectedRows().get(0).getData().getEntity();
     selectedRow._attributes._collection.cs_claimcreationinitiate.setValue(true);    
     var Roitext = selectedRow._attributes._collection.cs_roitext.getValue();
     var status  = selectedRow._attributes._collection.cs_claimstatus.getValue();

var entityFormOptions = {};
    entityFormOptions["formId"] = "1533E4B3-5087-ED11-81AD-002248175B80";
    entityFormOptions["entityName"] = "cs_claimrecordheader";

    entityFormOptions["windowPosition"] = 1;
    entityFormOptions["navbar"] = "entity";

    // Set default values 
    var formParameters = {};
    formParameters["cs_preapprovalreference"]=selectedRow.getEntityReference();
    formParameters["cs_claimstatus"] = status;
formParameters["cs_roitext"] = Roitext ;
       Xrm.Navigation.openForm(entityFormOptionsformParameters).then(
        function (success) {
            console.log(success);
        },
        function (error) {
            console.log(error);
        });
}
  • pskateel Profile Picture
    pskateel 102 on at
    RE: i have created js script in dynamics 365 when we click on button on select of record it will create record in other table but im unable to copy status choice column and Roitext text column to another table column

    Thank you so much for the help it worked

  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 10,203 Super User 2025 Season 1 on at
    RE: i have created js script in dynamics 365 when we click on button on select of record it will create record in other table but im unable to copy status choice column and Roitext text column to another table column

    Hello pskateel,

    It is a request please don't create duplicate posts. I have already provided the solution please refer that.

    community.dynamics.com/.../i-want-to-create-a-copy-of-status-column-to-another-column-using-js-script-in-dynamics-365-when-we-click-on-button-on-select-of-record-i-was-able-to-copy-primary-column-using-below-code

    Thank You,

    Amit Katariya.

  • Verified answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 10,203 Super User 2025 Season 1 on at
    RE: I want to create a copy of status column to another column using js script in dynamics 365 when we click on button on select of record , i was able to copy primary column using below code

    Hey Buddy,

    I looked into your code and implemented a new code using an example. you can revise your code by referring below snippet.

    I have My custom button on the Opportunity entity and will create a "First" entity record when we will click on the button. Below JS will populate opportunity lookup and its status on the First entity record and redirect it to the new record.

    pastedimage1673617398349v1.png

    pastedimage1673617429550v2.png

    function createFirstRecord(SelectedControl)
    {
        var selectedRow = SelectedControl.getGrid().getSelectedRows().get(0).getData().getEntity();
        var entityFormOptions = {};
    
        var recordId = SelectedControl.getGrid().getSelectedRows().get(0).getData().getEntity().getId();
        var record = {};
    
        Xrm.WebApi.online.retrieveRecord("opportunity", "" recordId, "?$select=statecode,statuscode").then(
            function success(result) {
                console.log(result);
                // Columns
                var opportunityid = result["opportunityid"]; // Guid
                var statecode = result["statecode"]; // State
                var statecode_formatted = result["statecode@OData.Community.Display.V1.FormattedValue"];
                var statuscode = result["statuscode"]; // Status
                var statuscode_formatted = result["statuscode@OData.Community.Display.V1.FormattedValue"];
    
                var record = {};
                record["ak_Opportunity@odata.bind"] = "/opportunities(" opportunityid ")"; // Lookup
                record.ak_opportunitystatus = statuscode_formatted; // Text
    
                Xrm.WebApi.online.createRecord("ak_first", record).then(
                    function success(result) {
                        var newId = result.id;
                        var entityFormOptions = {};
                        entityFormOptions["entityName"] = "ak_first";
                        entityFormOptions["entityId"] = newId;
    
                        // Open the form.
                        Xrm.Navigation.openForm(entityFormOptions).then(
                            function (success) {
                                console.log(success);
                            },
                            function (error) {
                                console.log(error);
                            });
                    },
                    function(error) {
                        console.log(error.message);
                    }
                );
            },
            function(error) {
                console.log(error.message);
            }
        );
    }
     

    As you can see we will start with our function and will pass the Selected Control from ribbon.

    Then we will get the GUID of first selected record using line number 6. As we have GUID of the record we will get all the details which we will need like status and status code of opportunity(refer line no 9).

    Then once I have the record, we will create first record by passing the GUID and status of opportunity (refer line no 19 to 24).

    once "First" entity record created, we will redirect from opportunity form to the newly created record using GUID and openform API(line no 31).

    I have saw your code and there is a issue and the issue is that you don't have status and Pre Approval Reference field on the view and because of that your below code will not work.

    var Roitext = selectedRow._attributes._collection.cs_roitext.getValue();
    var status  = selectedRow._attributes._collection.cs_claimstatus.getValue();

    To resolve that you can use retrieveRecord API's(refer line no 9.). In my case it will return opportunity statuscode and statecode.

    once you have the data you can pass it to the your parameter object.

    Thank you,

    Amit katariya

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: i have created js script in dynamics 365 when we click on button on select of record it will create record in other table but im unable to copy status choice column and Roitext text column to another table column

    I would recommend using Xrm.WebApi.retrieveRecord to get values of fields since you have selected record id in your code.

  • pskateel Profile Picture
    pskateel 102 on at
    RE: i have created js script in dynamics 365 when we click on button on select of record it will create record in other table but im unable to copy status choice column and Roitext text column to another table column

    Roitext is Text type field

    status is choice type field

    this two fields are not present in the grid, so is there any other way to get this values?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: i have created js script in dynamics 365 when we click on button on select of record it will create record in other table but im unable to copy status choice column and Roitext text column to another table column

    Hello,

    What are the types for "Roitext" and "Status"? And one more thing - if a particular field is not present in the grid - the value of it won't be available for getting it the way you use.

  • pskateel Profile Picture
    pskateel 102 on at
    RE: I want to create a copy of status column to another column using js script in dynamics 365 when we click on button on select of record , i was able to copy primary column using below code

    claim header form LOGICAL NAME

    Pre Approval Reference    -  cs_preapprovalreference

    status                                 - cs_claimstatus

  • Amit Katariya007 Profile Picture
    Amit Katariya007 10,203 Super User 2025 Season 1 on at
    RE: I want to create a copy of status column to another column using js script in dynamics 365 when we click on button on select of record , i was able to copy primary column using below code

    Can you provide me logical names of those 2 fields which are present on the claim header form.

  • pskateel Profile Picture
    pskateel 102 on at
    RE: I want to create a copy of status column to another column using js script in dynamics 365 when we click on button on select of record , i was able to copy primary column using below code

    im not sure what excatly im supposed to add, i just want to update one status field, im able to update primary column

  • Amit Katariya007 Profile Picture
    Amit Katariya007 10,203 Super User 2025 Season 1 on at
    RE: I want to create a copy of status column to another column using js script in dynamics 365 when we click on button on select of record , i was able to copy primary column using below code

    You have to provide Entity data or we can say data for claim header.

    refer below article where we are providing various other details in "parameters" variable. In your case it will be part of entityFormOptions variable.

    learn.microsoft.com/.../set-field-values-using-parameters-passed-form

    carldesouza.com/.../

    Thank You,

    Amit Katariya

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans