0

Given this code:

var Container = CRM.GetBlock("Container");
    var CustomCommunicationDetailBox = CRM.GetBlock("CustomCommunicationDetailBox");
    Container.AddBlock(CustomCommunicationDetailBox);

    if(!Defined(Request.Form)){
        CRM.Mode=Edit;
    }else{
            CRM.Mode=Save;
        }

    CRM.AddContent(Container.Execute());
    var sHTML=CRM.GetPageNoFrameset();
    Response.Write(sHTML);

Im calling this .asp page with this parameters but does not seems to work

popupscreeens.asp?SID=33185868154102&Key0=1&Key1=68&Key2=82&J=syncromurano%2Ftabs%2FCompany%2FCalendarioCitas%2Fcalendariocitas.asp&T=Company&Capt=Calendario%2Bcitas&CLk=T&PopupWin=Y&Key6=1443Act=512

Note the Key6=Comm_Id and Act=512??? which i believe it is when editing?

How can i achieve to fill the screen's field with entity dada? In this case it is a communication entity

Gianni Di Falco
  • 165
  • 1
  • 10

1 Answers1

1

In order to populate a custom screen with data, you need to pass the data to the screen.

First, you need to get the Id value. In this case, we're getting it from the URL:

var CommId = Request.QueryString("Key6") + '';

We're going to put a few other checks in though. These are mainly to handle scenarios that have come up in different versions or from different user actions.

// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
    CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}
// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
    CommId = 0;
} else if(CommId.indexOf(",") > -1){
    CommId = CommId.substr(0,CommId.indexOf(","));
}

Certain user actions can make the URL hold multiple Ids in the same attribute. In these cases, those Ids are separated by commas. So, if the Id is not defined, we check if there is a comma in it. If there is, we take the 1st Id.

After we have the Id, we need to load the record. At this point, you should have already checked you have a valid id (E.g. not zero) and put some error handling in. In some pages you may want to display an error, in others you may want to create a new, blank record. This gets the record:

var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);

After that, you need to apply the record to the screen. Using your example above:

CustomCommunicationDetailBox.ArgObj = CommRecord;

Adding all that to your script, you get:

var CommId = Request.QueryString("Key6") + '';

// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
    CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}

// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
    CommId = 0;
} else if(CommId.indexOf(",") > -1){
    CommId = CommId.substr(0,CommId.indexOf(","));
}

// add some error checking here

// get the communication record
var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);

// get the container and the detail box
var Container = CRM.GetBlock("Container");
var CustomCommunicationDetailBox = CRM.GetBlock("CustomCommunicationDetailBox");

// apply the communication record to the detail box
CustomCommunicationDetailBox.ArgObj = CommRecord;

// add the box to the container
Container.AddBlock(CustomCommunicationDetailBox);

// set the moder
if(!Defined(Request.Form)){
    CRM.Mode=Edit;
} else {
    CRM.Mode=Save;
}

// output
CRM.AddContent(Container.Execute());
var sHTML=CRM.GetPageNoFrameset();
Response.Write(sHTML);

However, we would advise putting in more error/exception handling. If the user is saving the record, you will also need to add a redirect in after the page is written.

Six Ticks Support

  • Nice, but when i try to save the changes it gives an error on line 21: `eWare.eWareBlockContainer error '8000ffff' [SafeCall Exception]: Error de SQL`. Line 21 is `CRM.AddContent(Container.Execute());` – Gianni Di Falco Sep 19 '16 at 07:08
  • What does the SQL log say? – Six Ticks Limited Sep 19 '16 at 12:37
  • Not captured in the moment. But i manged to do so this way: When the screen is in Edit mode, i just print all Sage CRM page with CRM.GetPageNoFrameSet() etc etc. Now when i click in the save button (i guess the action is set to the very same page) `Request.Form` is dfined so the screen is in Save mode and only then is where i `SaveChanges()` and close the popup, reload the parent opener wuindow etc etc (All without printing anything). I do not put all the code here because the space is too small – Gianni Di Falco Sep 20 '16 at 10:54