0 votes

Hi,

After speak with the Efficy support, I have to use a serverscript to generate html.
This serverscript will be call in a macro with a RunScript.

I prefer not to put so many html directly in the serverscript, I find that it is not a "good practice" and make the script less readable..
Is there a way to import html from a page in server script with Efficy 10.2 ?

Example :
serverscripts/Example.js

/* function called by <%RunScript(...)%> */
function GetCustomHtmlTable() {
  var EditHandle = Request.ContextHandle,
      HtmlTemplate = "IMPORT HTML FROM HTML FILE ? like pages/grid/HtmlTemplate.htm ?"

  /* some code to get the rights values */
  var name = Database.GetFieldValue(EditHandle, 'NAME'), // in this example : 'My custom header'
      description = 'some text',
      otherData = 'otherData...'

  /* Generate html and return it */
  return ParseTemplate(HtmlTemplate, name, description, otherData);
}

/* this function replace each %s in the template by the others params value in args */
function ParseTemplate(template) {
  var args = [].slice.call(arguments, 1),
      i = 0;

  return template.replace(/%s/g, function() {
      return args[i++];
  });
}

HtmlTemplate.htm

<div class="CustomClasses">
  <div class="header">%s</div>
  <div class="body">%s</div>
  <div class="footer">%s</div>
</div>

This will return :

<div class="CustomClasses">
  <div class="header">My custom header</div>
  <div class="body">some text</div>
  <div class="footer">otherData...</div>
</div>
asked in WorkFlow / Serverscript by (245 points)

1 Answer

0 votes

You asked a very relevant question, it's indeed not a good idea to generate a lot of HTML inside a serverside script.

You have two options:

Succes!

answered by (6.9k points)
In fact, I have to completely customize GetRelationGrid(Prod) in TabContentProds.

My problem is that I need 2 DataSet:
- Btch (Relation = BTCH_OPPO) which will be totally displayed so I could use it in HTML with GetRelationGrid (Btch)
- Prod (Relation = PROD_OPPO) which will be partially displayed for each Btch.
By "partially", I mean that the Prod dataset must be filtered on "F_BATCH = K_BATCH".
To be clearer with the exact customizations, it's like I have to display the PROD_OPPO relations in OppoEdit, but split into several tables (where Btch will be "headers")

How does Request.getMacro work?
I can use it as Request.getMacro ('MyMacro', 'Oppo', 'Prod', ???)
Does Request.getMacro allow to filter? And what can I put as 'values'.
I have never used the TEnhStringList, how to use it in a macro? I can not find an example in the standard code

I have already tried this customization article but it does not work (I edited it)
https://overflow.efficy.com/?qa=3845/cutomize-oppoedit-getrelationgrid-custom-entity-products
I wrote the script server skeleton if it can help you understand what kind of display I want
1,173 questions
1,432 answers
1,726 comments
325 users