Update Free Text fields using the onchange script 7.3 SP2

Can anyone point me in the right direction on how I can set up the onchange script in the first field of the Free Text window in Orders and Quotes to extract the values from another opportunity and fill them into the Free Text fields?

I've added a Advanced Search Select field to the Free Text screen in Quotes and Orders to select a different opportunity. It pops up the list and fills in the resulting value in the field. It triggers the onchange script, but that's where it stops working. We use this to bring in the initial values from the other opportunity record to bring them into a new line on the quote. Can anyone tell me how I can extract the values from the second opportunity and fill out the fields in the Free text screen? I did it in prior versions by setting up an ASP page using an iFrame where I sent the opportunity ID to the ASP page and extracted all the data in the ASP page, which populated the free text item screen. The code will not work in 7.3. It brings up a blank screen and does not process.

As a side note, I can do it without a problem on other screens such as the opportunity and company screens. Just the Free Text screen seems to be a problem.

Thanks,

Kelly

  • 0

    It sounds like you need the OnChange script to do an ajax call to an asp or custom dotnet. The asp or custom dotnet should get the required opportunity and return the text data as either xml or json formatted object to the script which can then set the free text fields.

  • 0

    Are you familiar with the client side API? Have you got as far as getting the on change script on the lookup to the oppo field to write the newly selected id into the target field? If you have got that far you are half way home. To do the Ajax call you can use crm.sdata() to pull back the oppo details and then write into the target field.

  • 0

    Paul, Thanks for responding. My problem appears to be on how to format the method to call the ASP and return to the screen. Do you have an example of how to call the ASP code from the onchange script so it will either update the free text item fields within the ASP or return the values so I can do it in the onchange script?

  • 0

    Jeff, thanks for answering. I am familiar with the client side API. (familiar but not proficient, obviously) The advanced search select returns the opportunity ID I want, but after that I am breaking down. I have that ID, so I can write it into a new field, but I have not figured out how to use that ID and crm.sdata() to pull back the other opportunity fields I need to write back to the free text fields.

  • 0

    Using Jeff's SData idea, something like the following in your opportunity field ChangeScript:

    var OppoID = crm.fields("").value();

    var GotOppo = function (OppoRec) {

    crm.fields("orit_description").value(OppoRec.);

    }

    crm.sdata({

    entity: "opportunity",

    id: OppoId,

    success: GotOppo

    });

    You need to change the parts between <> characters to put in the relevant field names (and also remove the <> characters).

  • 0

    Paul,

    Thanks again for helping. I tried doing this before using an example Jeff posted regarding Ajax calls and I could not get it to work. I'm sure I'm just missing something basic, but I can't see it!

    The field I am using in the orderitems table is "orit_oppolink". It is an advanced search select field. If I used this code in the onchange script it does not return the value.

    var OppoID = crm.fields("orit_oppolink").value();

    crm.infoMessage(OppoId);

    It will return the value if I use this code:

    var OppoId = document.EntryForm.orit_oppolink.value;

    crm.infoMessage(OppoId);

    When I put my fields into the code you provided (below) it does not update the field on the screen. If I have it display the return value using infoMessage it is always blank. I made sure there is data in the oppo_partselected field. If I use the oppoId from the document.EntryForm, the function still does not work. Even if I hardcode it with the actual oppo_opportunityid value, the function still does not work.

    var OppoID = crm.fields("orit_oppolink").value();

    var GotOppo = function (OppoRec) {

    crm.fields("orit_description").value(OppoRec.oppo_partselected);

    }

    crm.sdata({

    entity: "opportunity",

    id: OppoId,

    success: GotOppo

    });

    I still have about half my hair left...

  • 0

    I notice there is a typo in the code I posted - in the first line, the variable OppoID has a capital 'D' whereas later in the script it has a lower case 'd'. The spelling needs to be consistent, so change one of them to match the other.

    crm.fields("").value(); definitely works for me.

    I'll check out the crm.sdata() method.

  • 0

    I can't get the crm.sdata() function to work. Eventually I managed to work out how to get the error information and TomCat is returning "403 - Access to the specified resource () has been forbidden.".

    I've logged this with Sage Dev Support, but since we can no longer telephone them it has to be via email so I can't say when I will receive a response.

  • 0

    Paul,

    Thank you. I wouldn't have been that confident it was a system problem. I think there is something different about how they approached the orderitems. Not sure what is different. I feel a little better knowing you had some trouble with it as well.

    Thank you,

    Kelly

    Kelly Hamann

    WAC Solution Partners

  • 0

    To get the error message back from the crm.sdata() call, use the error option, eg:

    crm.sdata({

    entity: "opportunity",

    id: oppoId,

    success: gotOppo,

    error: function(err){crm.infoMessage(err.responseText);}

    });

    It might be useful to know if you get the same error.

  • 0

    Paul,

    I received a different error:

    Server Error

    502 - Web server received an invalid response while acting as a gateway or proxy server.

    There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.

    Kelly

  • 0

    I received a response from Sage Developer Support this afternoon. Rather worryingly, it started "We don't fully support sData ...". What a joke - we pay enormous fees for developer support and they take two days to tell me that they don't support their own product. The response email went on to tell me to post my question in this forum. Really, you couldn't make it up.

    So here goes - does anyone have any idea how to go about debugging error messages (see above for examples) resulting from sdata calls?

    Thanks

  • 0

    Paul,

    Thank you for spending your time on this. That response is disappointing. Aside from the fees, it is embarassing with my customers when I tell them I cannot do something because the software doesn't work the way it is supposed to. What do you say when they ask, "Why don't they fix it?". I've tried several work arounds but so far I have been unable to get them to work either. I can't give up because they need it so I will try to think of another approach.

    Kelly Hamann

    WAC Solution Partners

  • 0

    Hurray!! I've managed to get the crm.sdata() ajax call to work at last - on a different CRM install, however, so my problem on the other install where it still doesn't work may be a version issue (CRM7.3 vs CRM7.3SP2).

    The bad news is that the response of the sdata call seems to be cached by the browser (IE11 in this case). I noticed in Fiddler that the first request produced an sdata request, but subsequent requests for the same CRM record didn't. I then edited the CRM record (an opportunity) then went back and re-selected it in my SSA field and the sdata call retrieved the old data. Logging out/back into CRM (different SID, so different request) then returned the updated CRM record from the sdata call.

    I therefore wouldn't recommend using crm.sdata() unless you know that the data will be static or that cacheing the response can be prevented. Does anyone know if this can be done?

    This is the script that finally worked:

    var oppoId = crm.fields("comp_oppoid").value();

    function gotOppo(oppoRec){

    alert("gotOppo! Description = "+oppoRec.oppo_description);

    crm.fields("comp_oppodesc").value(oppoRec.oppo_description);

    }

    crm.sdata({

    entity: "opportunity",

    id: oppoId,

    success: gotOppo,

    error: function(err){crm.infoMessage(err.responseText);}

    });

    Obviously this is run in the OnChange script of an SSA field (comp_oppoid) in a Company context.

    I will continue to use ajax calls using JQuery functions. It seems to be more reliable and I can control the response cacheing.

  • 0

    Thanks for continuing to work on this. I assume it is just a bug in the SP2 code then. I am probably stuck then. I used that update to fix other bugs! You mentioned that you would continue to use ajax calls using JQuery functions. Do you have an example of how I could do this same function with that method so I can avoid the bugs in the sdata methods?

    Thanks,

    Kelly Hamann

    WAC Solution Partners

  • 0

    Update - actually, the crm.sdata() function *does* work on my CRM7.3 install if I run the script from a Company context but not if I run it from a custom entity. There is a difference in the sdata requests:

    From Company:

    GET /sdata/crmj/sagecrm/-/opportunity('76')?SID=28441089346363 HTTP/1.1

    From custom entity (asp page):

    GET /sdata/crmj/sagecrm/-/opportunity('76')?SID=28441089346363%2526Key0%3D1%2526Key1%3D119%2526Key2%3D140%2526J%3DEntity%2FCompanyEntity.asp%2526E%3DEntity%2526T%3DCompany%2526Capt%3DEntity HTTP/1.1

    Clearly there is a lot of additional baggage attached to the custom entity sdata request, but up to the end of the SID they are identical. I guess that the additional baggage appended to the SID causes an authentication failure resulting in the 403 error. I haven't managed to work out how to prevent this yet - hopefully someone from Sage might chip in with the answer.

  • 0

    The issue I am having does not involve a custom entity at this time. I am working with the Orderitems table and the Opportunity table. Perhaps I am having a completely different issue. I will experiment with the sdata methods on the company table and see if I am able to make this type of sdata request work there. The error I get is different than yours:

    502 - Web server received an invalid response while acting as a gateway or proxy server.

    Thanks again,

    Kelly Hamann

    Sage Solution Partners