<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged import-script</title>
<link>https://overflow.efficy.io/?qa=tag/import-script</link>
<description>Powered by Question2Answer</description>
<item>
<title>Impossible to import file without extension in task scheduler service</title>
<link>https://overflow.efficy.io/?qa=6519/impossible-import-file-without-extension-scheduler-service</link>
<description>&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;I want to import some utile files in my script runned by &quot;task scheduler service&quot;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/*
@import General from &quot;dataSynchro/general&quot;;
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But I get this error : &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Error: Cannot open file &quot;[...]\efficy\serverjs\dataSynchro\general&quot;.&lt;br&gt;
  Le fichier spécifié est introuvable&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If I change for this :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/*
@import General from &quot;dataSynchro/general.js&quot;;
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;it works. I don't understand why I couldn't use this notation while I see in the documentation that I can : &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://help.efficy.io/edn/admin/scpr_taskscheduleraddscheduledscript&quot;&gt;Documentation&lt;/a&gt;&lt;br&gt;
&lt;img src=&quot;https://overflow.efficy.io/?qa=blob&amp;amp;qa_blobid=11975129511579841757&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;

&lt;p&gt;If someone could explain me what I did wrong, it will be really appreciated :) &lt;br&gt;
Thanks for your help ;) &lt;/p&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=6519/impossible-import-file-without-extension-scheduler-service</guid>
<pubDate>Wed, 27 Apr 2022 12:06:01 +0000</pubDate>
</item>
<item>
<title>1st import script for a DataSynchro</title>
<link>https://overflow.efficy.io/?qa=2818/1st-import-script-for-a-datasynchro</link>
<description>&lt;p&gt;Hi all!&lt;/p&gt;

&lt;p&gt;I wanted to train me with scripting (import data from Excel file with Data Synchro)&lt;br&gt;
 Excel:&lt;br&gt;
Company;External ID;COMPANY;Contact external Id;FIRSTNAME;LASTNAME&lt;br&gt;
1 | COMP &amp;amp; CIE | 1 | BERNARD | A.&lt;br&gt;
1 | COMP &amp;amp; CIE | 2 | BART | B.&lt;br&gt;
2 | IKEA | 3 | ABDUL | C.&lt;br&gt;
2 | IKEA | 4 | WORLD | D.&lt;/p&gt;

&lt;p&gt;Objectives: insert this data in the DB, link the Contact to the Company, and link all these new entities to the same Publication&lt;/p&gt;

&lt;p&gt;this script&lt;br&gt;
I have some questions:&lt;br&gt;
- Does my script respect good practices&lt;br&gt;
- I have difficulties to understanding the difference between Relation (with AddLink2) and Details (with InsertDetail2). For me Detail is a &quot;type&quot; of relation&lt;br&gt;
A Detail is the sub Entity in the selected Entity right?&lt;br&gt;
- in InsertDetail2 what does the last parameter?? I don't undersand the &quot;automatically link the contact’s main company&quot;&lt;/p&gt;

&lt;p&gt;Finally, DataSync Tool thorws an Exception when i run it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[15:52:44.744]     4 Records Found
[15:52:44.744]   Handling Record &quot;MAXIME&quot;...
[15:52:52.076] 
[15:52:52.076] *** ERROR ***
[15:52:52.076] Error while creating or modifying destination record.
[15:52:52.076] Error: WKFL-2142 Error while executing Script &quot;EOleException&quot; at line 16 char 5.
Message: &quot;SLC_Publ_Cont_750
Cannot add a new Relation

ErrorContext
=============================     
EDatabaseError 0
L'instruction INSERT est en conflit avec la contrainte FOREIGN KEY &quot;FK_PUBLICATIONS_PUBL_CONT1&quot;. Le conflit s'est produit dans la base de données &quot;TESTFORMATION&quot;, table &quot;ADMINFORMATION.PUBLICATIONS&quot;, column 'K_PUBLICATION'

Error
=============================     
EEfficyTableViewException 1116
(ENTT-1616) SLC_Publ_Cont_750
Cannot add a new Relation
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;my script:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var PUBLICATION_KEY = 2;

function EfficyImportRecord(DataStore) {
  var companyKey = DataStore.FindExistingEntity('Comp');
  var compEdit = Database.OpenEditContext(ntComp, companyKey);
  try {
    var dsComp = Database.GetMasterDataSet(compEdit, 0);
    dsComp.Edit();
    companyKey = dsComp.FieldByName('K_COMPANY').AsFloat; // Dans le cas où on crée un nouvel enregistrement, sinon la valeur était déjà initialisée par la méthode DataStore.FindExistingEntity
    dsComp.FieldByName('F_EXTERNALID').AsString = DataStore.AsString('Company External ID');
    dsComp.FieldByName('NAME').AsString = DataStore.AsString('COMPANY');

    // Pour identifier clairement les sociétés impactées par la datasynchro, la lier à une publication add-hoc
    Database.AddLink2(ntPubl, ntComp, PUBLICATION_KEY, companyKey, true);


    Database.CommitChanges(compEdit, false);
  } 
  finally
  {
    Database.CloseContext(compEdit);
  }


  var contKey = DataStore.FindExistingEntity('Cont');
  var contEdit = Database.OpenEditContext(ntCont, contKey);
  try {
    var dsCont = Database.GetMasterDataSet(contEdit, 0);
    dsCont.Edit();
    contKey = dsCont.FieldByName('K_CONTACT').AsFloat;
    dsCont.FieldByName('F_EXTERNALID').AsString = DataStore.AsString('Contact external Id');
    dsCont.FieldByName('NAME').AsString = DataStore.AsString('LASTNAME');
    dsCont.FieldByName('FIRSTNAME').AsString = DataStore.AsString('FIRSTNAME');

    Database.InsertDetail2(contEdit, ntPubl, PUBLICATION_KEY, false);  //passer false a true??
    Database.InsertDetail2(contEdit, ntComp, compKey, false);

    Database.CommitChanges(contEdit, false);
  } 
  finally
  {
    Database.CloseContext(contEdit);
  }


  return true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Thanks a lot!&lt;/p&gt;
</description>
<category>Database</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2818/1st-import-script-for-a-datasynchro</guid>
<pubDate>Thu, 07 Dec 2017 15:30:13 +0000</pubDate>
</item>
</channel>
</rss>