cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Dyna03
Frequent Visitor

How to save modification on page onload on quotedetail page?

Hello everyone,

i have very important task, i am stuck in this, please help me in this.

 

Dyna03_1-1663740303108.png

 

this is my quote product, in this product have spec tab which is related to quote product  specification.

 

when ever i update or modified this specification and save this quote product , and then reload the page, then changes are gone.

 

i want do the JavaScript code on page onload event, and i want changes when i refresh a page.

 

Thanks

 

 

5 REPLIES 5
ben-thompson
Memorable Member
Memorable Member

Are these items all part of the same table or are some of the fields being pulled from a different table for display purposes?

And you say you want to use a Javascript an onload event - does that code currently exist and what does it do?

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".
Mira_Ghaly
Dual Super User
Dual Super User

@Dyna03 

Specifications looks like a field on the from of quote product..is that correct?

I don't understand what you need from the onload event as in normal scenarios this should be reflected automatically upon save you can see the new changes.

 

I believe there might be something in the background clearing the field value.

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here
gowrihalan04
Helper V
Helper V

@Dyna03 If you are setting that field value via Javascript on Onload event for the first time, Then put in form type(create form, update form) condition.

Or if you want to set that field when it does not contains any data then add null check.

If you manually filling the field and it is getting removed when form is loading then you need to check for existing JS registered on that form has logic on that particular field.

rampprakash
Super User
Super User

Hi @Dyna03 

 

You can use IsDirty function to get the unsaved field logical name and proceed your steps.

 

Syntax :

 

Xrm.Page.data.entity.getIsDirty()

 

 

Url for Reference: https://carldesouza.com/checking-isdirty-dynamics-365-using-javascript/

 

 

Please mark as Answer if it is helpful and provide Kudos


Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA
Follow me on Twitter : @rampprakashd
Blog : https://microsoftcrmtechie.blogspot.com

 

@gowrihalan04  yes i have alread one js on form onload event

belove is code on quoteine onload 

function onLoadSetSpec(executionContext) {
	debugger;
	var formContext = executionContext.getFormContext();
	var quoteLookup = formContext.getAttribute("quoteid").getValue();
	var quoteDetailIDAX = formContext.getAttribute("sar_quotedetailidax").getValue();
	if ((quoteLookup != null)) {
		var quoteGUID = quoteLookup[0].id;
		quoteGUID = quoteGUID.replace('{', '').replace('}', '');

		Xrm.WebApi.online.retrieveRecord("quote", quoteGUID, "?$select=name,revisionnumber,sar_quoteidax,statecode").then(
			function success(result) {
				var name = result["name"];
				var revisionnumber = result["revisionnumber"];
				var revisionnumber_formatted = result["revisionnumber@OData.Community.Display.V1.FormattedValue"];
				var quoteIDAX = result["sar_quoteidax"];
				var statecode = result["statecode"];
				var statecode_formatted = result["statecode@OData.Community.Display.V1.FormattedValue"];

				var previousRevionNumber = revisionnumber - 1

				Xrm.WebApi.online.retrieveMultipleRecords("quote", "?$filter=revisionnumber eq " + previousRevionNumber+ " and statecode eq 3  and  sar_quoteidax eq '" + quoteIDAX + "'").then(
					function success(results) {
						for (var i = 0; i < results.entities.length; i++) {
							var quoteid = results.entities[i]["quoteid"];
							//alert("Last Close Quote : " + quoteid);
							if (quoteid != null) {
								Xrm.WebApi.online.retrieveMultipleRecords("quotedetail", "?$select=quotedetailid,quotedetailname,_quoteid_value,sar_specificationsenglish,sar_specificationsfrench,sar_specsreviewed&$filter=_quoteid_value eq '" + quoteid + "' and  sar_quotedetailidax eq '" + quoteDetailIDAX + "'").then(
									function success(results) {
										for (var i = 0; i < results.entities.length; i++) {
											var quotedetailid = results.entities[i]["quotedetailid"];
											var quotedetailname = results.entities[i]["quotedetailname"];
											var _quoteid_value = results.entities[i]["_quoteid_value"];
											var _quoteid_value_formatted = results.entities[i]["_quoteid_value@OData.Community.Display.V1.FormattedValue"];
											var _quoteid_value_lookuplogicalname = results.entities[i]["_quoteid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
											var sar_specificationsenglish = results.entities[i]["sar_specificationsenglish"];
											var sar_specificationsfrench = results.entities[i]["sar_specificationsfrench"];
											var sar_specsreviewed = results.entities[i]["sar_specsreviewed"];
											var sar_specsreviewed_formatted = results.entities[i]["sar_specsreviewed@OData.Community.Display.V1.FormattedValue"];
                                                                        formContext.getAttribute("sar_specificationsenglish").setValue(sar_specificationsenglish);
							                formContext.getAttribute("sar_specificationsfrench").setValue(sar_specificationsfrench);
										}
									},
									function(error) {
										Xrm.Utility.alertDialog(error.message);
									}
								);
							}
						}
					},
					function(error) {
						Xrm.Utility.alertDialog(error.message);
					}
				);

			},
			function(error) {
				Xrm.Utility.alertDialog(error.message);
			}
		);
	}
}

 

 

I have 2 custom field in quoteline- sar_specificationsenglish and  sar_specificationsfrench

 

if a update this 2 field on quoteline and save quote line and after revise a quote, then changes were gone.

so i write that code for revise quote. 

 

Now the problem with draft quote.

 

my quote is on draft state, and i modified those two field on quoteline. and save that form.

 

after refresh this page, then changes are gone 

 

so what to do for this issue

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (3,034)