Opportunity Adding New Panel [SafeCall Exception]

Help! I am getting a [SafeCall Exception] error message on the screen after creating a new opportunity.

This is the error that I am getting.

[SafeCall Exception]: SQL Error
oppo_dummy jscript error: [SafeCall Exception]: SQL Error Line: 38 Char: 0
[SafeCall Exception]: SQL Error
oppo_dummy jscript error: [SafeCall Exception]: SQL Error Line: 38 Char: 0

I am using the oppo_dummy field to add a new panel to the Opportunity summary screen. I have used the following post to assist me with getting the panel on the screen. https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2016/11/02/adding-a-new-panel-to-a-summary-screen-e-g-company-summary.aspx

The panel does not display during the insert of the opportunity. However, I need it to display immediately after the opportunity is inserted.

The opportunity gets created and the panel displays on the screen and appears as expected (ie everything "looks" good). However, I also get the SafeCall Error message displayed on the screen and I cannot determine why. I have reviewed the logs and they are not indicating an error.

The error appears to be repeated twice (on the screen). Below is the code that I have in the oppo_dummy field. I have compacted the lines to save space. Line 38 is actually a blank line right after the following line of code -- else if (OppoType == "Acquisition")

Where might I have gone wrong with the below code? Any assistance would be greatly appreciated! Thank you!

if (Values("Act") == 260 || Values("Act") == 520 || Values("Act") == 1190 && Values("Mode") == 3)
{
var OppoID = CRM.GetContextInfo("Opportunity", "oppo_opportunityid");
var OppoRecord = CRM.FindRecord("Opportunity","oppo_opportunityid=" + OppoID);
var OppoType = Values("oppo_opportunitytype");
if (OppoType == "Service"){
var NewDetailsPanel = CRM.GetBlock("OppoDetailsService");
}
else if (OppoType == "PortfolioLeasing")
{
var NewDetailsPanel = CRM.GetBlock("OppoDetailsLeasing");
}
else if (OppoType == "Acquisition")
{
var NewDetailsPanel = CRM.GetBlock("OppoDetailsAcquisition");
}
NewDetailsPanel.DisplayButton("1") = false;
NewDetailsPanel.DisplayForm = false;
var strBlockHTML = NewDetailsPanel.Execute(OppoRecord);
Caption = "<script" + ">";
Caption += "var strPanelHTML ='";
Caption += strBlockHTML;
Caption += "';";
Caption += "<" + "/script>";
}
else {
Hidden = true;
}

  • 0

    Hi Michelle,

    Two things I'd take a look at:

    1) Line #8 of your code - "var OppoType = Values("oppo_opportunitytype");". If this is a custom field, then it should be fine, but if not I do believe the default column name is "oppo_type".

    2) If item 1 above is fine, I'd begin calling out your variables into an error string before arriving at the "if" statement. Something simply along the lines of...

    var sysAct = Values("Act");

    var sysMode = Values("Mode");

    var OppoType = Values("oppo_type");

    ErrorStr += "System Action = " + sysAct + ". Mode = " + sysMode + ". Type = " + OppoType + ".";

    Hopefully that will at least give you some insight of what might be going on. The code itself looks pretty solid otherwise. Hope this helps!

  • 0

    Basil:

    Thank you so much for the suggestions. It is nice to know that another set of eyes thinks the code looks solid because I am banging my head on my desk! :-)

    The field oppo_opportunitytype is a custom field. The field oppo_type was already being used for identification of the oppo before I needed to distinguish between three different types of workflows (Acquisition, PortfolioLeasing, Service). Therefore, I created the oppo_opportunitytype field for the purpose of identifying the workflow.

    In regards #2, thank you for this. When I am trouble shooting, I do like to display my variables on the screen..but often forget exactly how to write it for where I am at (ie..asp page, create script, etc). (PS, I love that you put the punctuation in.)

    I added your code as is to my script right before the if statements and this is what I get returned.

    [SafeCall Exception]: SQL Error

    oppo_dummy jscript error: [SafeCall Exception]: SQL Error Line: 26 Char: 0

    System Action = 1190. Mode = 3. Type = Acquisition.

    [SafeCall Exception]: SQL Error

    oppo_dummy jscript error: [SafeCall Exception]: SQL Error Line: 26 Char: 0

    System Action = 1190. Mode = 3. Type = Acquisition.

    Here is the thing that is odd. The oppo gets created and the correct panel gets displayed on the screen. Everything "looks" perfect...except I get the "SafeCall Exception" on the screen. If I drop the code in JShint.com, it seems fine. I am wondering if the issue is that I don't have anything in my if statement to tell the system what to do if the field is not populated with one of the three workflow types. Since the workflow action will populate the type, this should never be the case. However, I am wondering if the system is telling me it does not like it none the less.

    Another odd thing is that the message appears twice. It seems like it should only appear once. Therefore, I am not sure what I have in the code that is causing it to appear twice...maybe that is the issue.

    I am going to try to add some code to tell the system what to do if oppo_opportunitytype is " ", undefined, or NULL and see if I still get the message. I will report back how that works out.

    One last thing of note, the issues appears to be related to Action 1190 (New Opportunity). After the oppo is created, if I come back to it through MyCRM or Search. This is the message that I see on the screen. Just the info from your code. No error message.

    System Action = 260. Mode = 1. Type = Acquisition.

    Any additional thoughts or assistance you can provide would be greatly appreciated. Again thank you!

  • 0

    Basil:

    I tried updating my if statements. However, it did not seem to make a difference in the message that was returned.

    After spending the last few hours trying to determine why the error exists. I decided to see if I could remove the error from the screen as there is no error in the logs and everything looks ok in the system so I cannot determine why the error is appearing. My issue seems to be related to the following action and mode... Action = 1190 (New Opportunity) and Mode = 3 (Save).

    After experimenting with different ways to try to get the message off the screen, I decided to try to redirect the page to Action (260) Opportunity Summary because no error appears when I am there ... just right after the oppo is saved (Action = 1190 and Mode = 3).

    Using Jeff's article from here .. How can I redirect to another screen immediately after entering a record? (for Sage CRM v7.1sp2 and earlier)

    community.sagecrm.com/.../how-can-i-redirect-to-another-screen-immediately-after-entering-a-record.aspx

    I removed this from my initial if statement -- Values("Act") == 1190 && Values("Mode") == 3

    And I added the following code to the custom content area of the OppoDetailBox. For now, it seems to be working perfectly for me. I still wish I knew why I was getting the error. However, I have spent way too much time trying to figure that out! :-)

    Basil...again thank you for your assistance, it did push me to look outside of my code script for a solution since there was not anything glaring in the code. Hope this solution helps someone else. I will post back if I run into any issues as I move along. Thanks!!

    (For the below script, I only changed where I wanted to end up. The original example had 271 which I changed to 260.

    if (window.addEventListener)

    {

    //firefox way of binding an event

    window.addEventListener("load", doRedirect, false)

    }

    else

    if (window.attachEvent)

    {

    //IE exclusive method for binding an event

    window.attachEvent("onload", doRedirect)

    }

    /////////////////////////////

    function doRedirect()

    {

    var bInEditMode=document.getElementById("oppo_description");

    var strSystemAction = GetKeyValue("act");

    var strMode = GetKeyValue("mode");

    var strSID = GetKeyValue("SID");

    if(!bInEditMode)

    {

    if ((strSystemAction == 1190 || strSystemAction == 261) && strMode == 3)

    {

    //alert(strSystemAction +"/"+strMode);

    var strTargetAction = "260"

    var strCurrentPath = document.location.href;

    var arrayContext = strCurrentPath.split('?');

    var strDLLPath = arrayContext[0];

    document.location.href= strDLLPath+'?SID='+strSID +"&act="+strTargetAction +GetKeys();

    }

    }

    }

    //////////////////////////////

    function GetKeyValue(querystringname)

    {

    var strPath = window.location.search.substring(1);

    var arrayKeys = strPath.split("&");

    for (var i=0;i

    {

    var arrayValue = arrayKeys[i].split("=");

    if (arrayValue[0].toLowerCase()== querystringname.toLowerCase())

    {

    return arrayValue[1];

    }

    }

    return "";

    }

  • 0

    I think we're possibly in danger of tossing the baby out with the bathwater here; the issue is caused by the fact that the code in your Create Script is executing more than once - I'm guessing you have Workflow enabled for Opportunities? - and OppoID is not set immediately. Basically, your code is failing twice and then working the third time round. It's slightly confusing because it's not the 'FindRecord' that fails, it's the NewDetailsPanel.Execute(OppoRecord) that's throwing the error.

    All we need to do is test if "var OppoID = CRM.GetContextInfo("Opportunity", "oppo_opportunityid");" gets us anything worthwhile - by concatenating it with an empty string and testing the overall length - e.g. ("" + OppoID).length.

    As such, my modified script is:

    if (Values("Act") == 260 || Values("Act") == 520 || Values("Act") == 1190 && Values("Mode") == 3)
    {
    var strBlockHTML, NewDetailsPanel;

    var OppoID = CRM.GetContextInfo("Opportunity", "oppo_opportunityid");

    if( ("" + OppoID).length > 0) {
    var OppoRecord = CRM.FindRecord("Opportunity","oppo_opportunityid=" + OppoID);
    var OppoType = Values("oppo_opportunitytype");

    if (OppoType == "Service"){
    NewDetailsPanel = CRM.GetBlock("OppoDetailsService");
    }
    else if (OppoType == "PortfolioLeasing")
    {
    NewDetailsPanel = CRM.GetBlock("OppoDetailsLeasing");
    }
    else if (OppoType == "Acquisition")
    {
    NewDetailsPanel = CRM.GetBlock("OppoDetailsAcquisition");
    }
    NewDetailsPanel.DisplayButton("1") = false;
    NewDetailsPanel.DisplayForm = false;
    strBlockHTML = NewDetailsPanel.Execute(OppoRecord);
    Caption = "
    Caption += "var strPanelHTML ='";
    Caption += strBlockHTML;
    Caption += "';";
    Caption += "<" + "/script>";
    }
    }
    else {
    Hidden = true;
    }

    (I've taken the liberty of moving some var declarations to the top of the code as well).

  • 0

    Chris:

    Thank you! Leave it to me to toss the baby out with the bath water! :-)

    Yes, workflow is enabled. My code is trying to distinguish between the three different types of oppo workflows to display a panel on the opportunity summary specifically related to each of the workflows. For some reason, I thought the panels would be easier to manage than trying to show/hide fields on the oppo detail box for each of the different oppo workflows. My down fall with this method is that I cannot view or modify the panel until the oppo has been created. Other than that, I am happy with the end result.

    I do follow what you are saying about the code being run three times..twice it fails, third time a charm. That makes sense as to why the error message is appearing twice. I will try your recommendations and see how it goes. I will let you know.

    Thank you!