Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable on the form based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.
Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable on the form based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.
The above steps worked well for my requirements.
Hi Sandy,
You could download community solution Workflow Tool to create an on-demand workflow for cloning/copying.
https://github.com/demianrasko/Dynamics-365-Workflow-Tools/blob/master/docs/Clone Record.md
Then you can run that workflow directly with web api or client api in custom button COMMAND settings,
Web API(just take the workflow guid as parameter)
https://carldesouza.com/calling-a-dynamics-365-workflow-through-javascript/
Client API
Please mark as verified if the answer is helpful, it would be greatly appreciated. :)
Regards,
Clofly
Hi Sandy,
I created a demo with account's Industry optionset field as example:
When selected option equals any one item among Account, Brokers or Consulting, then the button will be enabled/displayed.
and I found that there is no need to listen Save event, our function will be triggered automatically:
1. When selected option equals Business Services initially, the button is hidden,
2. When we change it to Consulting and click save, the button will appear.(or appear automatically if auto save enabled)
Your controlling logic could be below:
function rule() {
var flag = true;
var picklist = ["Accounting", "Brokers", "Consulting"];
var obj = Xrm.Page.getAttribute("industrycode");
if (obj != null) {
if (picklist.indexOf(obj.getText()) > -1) {
flag = false;
}
}
return flag;
}
The appearance controlling code is separate from clone/copy logic, so for the function of button itself,
you could decide which ways to achieve,
by Inogic's solution and integrate button appearance controlling code or
just adding the function that fetching the current record data with Xrm.Page.getAttribute then excute Xrm.webApi.createRecord to ribbon button COMMAND setting.
Regards,
Clofly
The above steps worked well thanks. I am looking for copy of record form and carry all the fields on to the new form with few fields set to be blank. Please share your thoughts on this
Thanks Clofly Mao for Response. Yes additional button is the ribbon button. The pick list field is Option set field and when the value of the field is "rejected" and the record is saved then the " Copy " button should be enabled on the form. For all other option set values the "Copy" button is disabled.
To achieve this you can use our one-click product – Click2Clone.
To find more about it you can click here.
Thanks!
Hi Sandy,
If your additional button means ribbon button:
You could work with a feature called Enable Rules in Ribbon Workbench solution, it allows us to add our custom javascript code to control whether display ribbon button.
1. After you have added a custom ribbon button, click Add Enable Rule button in COMMANDS setting for the custom button:
2. In ENABLE RULES setting, we add a step called CustomRule (custom javascript code), set Default and InvertResult to True,
(To see how to work with this setting, please read the article: https://www.magnetismsolutions.com/blog/adammurchison/2017/10/13/how-to-use-enable-rules-in-dynamics-365-with-the-ribbon-workbench)
then add our own function:
3. Display loigic:
If we return a true value in custom function, the button will not display, in example below, the button will be hidden.
Those above are how to achieve controlling button enabled/disabled, please add your own logic to control your button.
I'm glad to give more implementation if you could share more details of your requirement. :)
Regards,
Clofly
André Arnaud de Cal...
293,274
Super User 2025 Season 1
Martin Dráb
231,939
Most Valuable Professional
nmaenpaa
101,156
Moderator