Difference between revisions of "ImportManager class"
Nguyenduyan (talk | contribs) |
|||
(19 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{CGscriptClass_Template | {{CGscriptClass_Template | ||
− | |Name=ImportManager | + | |Name=<nowiki>ImportManager</nowiki> |
− | |Description=Import data and users. | + | |Description=<nowiki>Import data and users.</nowiki> |
− | |Constructors= | + | |InheritsFrom=object|Constructors= |
{{CGscriptConstructors_Template|Parameters= | {{CGscriptConstructors_Template|Parameters= | ||
− | {{CGscriptParameters_Template|Type=array|Name=Headers|Description=A list of string that are the header names|Comma=,}}{{CGscriptParameters_Template|Type=array|Name=data|Description=Data to import. An array of arrays of equal length as the headers|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=advancedMode|Description=Enable setting advanced settings - Requires special navigation access|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=groupResourceId|Description=Group to add users to new users to and/or sample rule. Set to 0 to not add to group}} | + | {{CGscriptParameters_Template|Type=array|Name=<nowiki>Headers</nowiki>|Description=<nowiki>A list of string that are the header names</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=array|Name=<nowiki>data</nowiki>|Description=<nowiki>Data to import. An array of arrays of equal length as the headers</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>advancedMode</nowiki>|Description=<nowiki>Enable setting advanced settings - Requires special navigation access</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>groupResourceId</nowiki>|Description=<nowiki>Group to add users to new users to and/or sample rule. Set to 0 to not add to group</nowiki>}} |
− | |Description=Make a new import with the given data}} | + | |Description=<nowiki>Make a new import with the given data</nowiki>}} |
|Methods= | |Methods= | ||
− | {{CGscriptMethods_Template|ReturnType= | + | {{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>GetPossibleAutoMasForData</nowiki>|Description=<nowiki>Get default automaps. First value is column name, second is actual import field</nowiki>}} |
− | {{CGscriptMethods_Template|ReturnType=Dictionary|Name=SetDataImportOptions|Parameters= | + | {{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>GetPossibleAutoMasForUser</nowiki>|Description=<nowiki>Get default automaps. First value is column name, second is actual import field</nowiki>}} |
− | {{CGscriptParameters_Template|Type=int|Name=projectQuestionnaireResourceId|Description=The resource Id of where the data should be added/updated|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=type|Description=How to treat when already have existing answer sheets. 1 for Zero or One AnswerSheet, 2 for delete existing and create new, 3 for mapping to rpqIdColumnName|Comma=,}}{{CGscriptParameters_Template|Type=string|Name= | + | {{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>Import</nowiki>|Description=<nowiki>Run the Import. Note that this will commit any pending changes</nowiki>}} |
− | |Description=Set specific options for importing data or altering existing data}} | + | {{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>SetDataImportOptions</nowiki>|Parameters= |
− | {{CGscriptMethods_Template|ReturnType=Empty|Name=SetDefaultNewUser|Parameters= | + | {{CGscriptParameters_Template|Type=int|Name=<nowiki>projectQuestionnaireResourceId</nowiki>|Description=<nowiki>The resource Id of where the data should be added/updated</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>type</nowiki>|Description=<nowiki>How to treat when already have existing answer sheets. 1 for Zero or One AnswerSheet, 2 for delete existing and create new, 3 for mapping to rpqIdColumnName</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>idColumnName</nowiki>|Description=<nowiki>Mapping for column name in case type is 3 or 4</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>isCommaSeparatedFormat</nowiki>|Description=<nowiki>Import multi questions as comma separated format</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=Dictionary|Name=<nowiki>mapping</nowiki>|Description=<nowiki>Mapping between header names and import names. If empty, automapping is used</nowiki>}} |
− | {{CGscriptParameters_Template|Type=string|Name=languageIso|Description=Default language|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=cultureIso|Description=Default culture|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=currency|Description=Default currency}} | + | |Description=<nowiki>Set specific options for importing data or altering existing data</nowiki>}} |
− | |Description=Defaults for new users. If empty or not set, uses the global defaults}} | + | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>SetDefaultNewUser</nowiki>|Parameters= |
− | {{CGscriptMethods_Template|ReturnType=Empty|Name=SetUserImportOptions|Parameters= | + | {{CGscriptParameters_Template|Type=string|Name=<nowiki>languageIso</nowiki>|Description=<nowiki>Default language</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>cultureIso</nowiki>|Description=<nowiki>Default culture</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>currency</nowiki>|Description=<nowiki>Default currency</nowiki>}} |
− | {{CGscriptParameters_Template|Type=string|Name=userIdColumnName|Description=The header name of the userId column|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=userNameMask|Description=The mask used to create new usernames - an advanced setting|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=generatePasswords|Description=Generate passwords during import|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importUserInfo|Description=Import or Update users|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importPhoneNumber|Description=Import or Update phonenumbers|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importAddress|Description=Import or Update addresses|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importPoints|Description=Import or Update points|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importQualification|Description=Import or Update qualifications|Comma=,}}{{CGscriptParameters_Template|Type=array|Name=permissions|Description=Determine which groups should have access to the new users|Comma=,}}{{CGscriptParameters_Template|Type=Dictionary|Name=mapping|Description=Mapping between header names and import names. If empty, automapping is used}} | + | |Description=<nowiki>Defaults for new users. If empty or not set, uses the global defaults</nowiki>}} |
− | |Description=OBSOLETE. Use the new overload with parentResourceId.}} | + | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>SetUserImportOptions</nowiki>|Parameters= |
− | {{CGscriptMethods_Template|ReturnType=Dictionary|Name=SetUserImportOptions|Parameters= | + | {{CGscriptParameters_Template|Type=string|Name=<nowiki>userIdColumnName</nowiki>|Description=<nowiki>The header name of the userId column</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>userNameMask</nowiki>|Description=<nowiki>The mask used to create new usernames - an advanced setting</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>generatePasswords</nowiki>|Description=<nowiki>OBSOLETE. Always false. Generate passwords during import</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importUserInfo</nowiki>|Description=<nowiki>Import or Update users</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importPhoneNumber</nowiki>|Description=<nowiki>Import or Update phonenumbers</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importAddress</nowiki>|Description=<nowiki>Import or Update addresses</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importPoints</nowiki>|Description=<nowiki>Import or Update points</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importQualification</nowiki>|Description=<nowiki>Import or Update qualifications</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=array|Name=<nowiki>permissions</nowiki>|Description=<nowiki>Determine which groups should have access to the new users</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=Dictionary|Name=<nowiki>mapping</nowiki>|Description=<nowiki>Mapping between header names and import names. If empty, automapping is used</nowiki>}} |
− | {{CGscriptParameters_Template|Type=string|Name=userIdColumnName|Description=The header name of the userId column|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=userNameMask|Description=The mask used to create new usernames - an advanced setting|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=generatePasswords|Description=Generate passwords during import|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importUserInfo|Description=Import or Update users|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importPhoneNumber|Description=Import or Update phonenumbers|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importAddress|Description=Import or Update addresses|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importPoints|Description=Import or Update points|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=importQualification|Description=Import or Update qualifications|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=parentResourceId|Description=Resource Id of the parent of the new users. Ignored if updating users|Comma=,}}{{CGscriptParameters_Template|Type=Dictionary|Name=mapping|Description=Mapping between header names and import names. If empty, automapping is used}} | + | |Description=<nowiki>OBSOLETE. Use the new overload with parentResourceId.</nowiki>}} |
− | |Description=Set specific options for importing new users or altering existing users}} | + | {{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>SetUserImportOptions</nowiki>|Parameters= |
− | {{CGscriptMethods_Template|ReturnType=string|Name=ToString|Description=The string representation of the object.}} | + | {{CGscriptParameters_Template|Type=string|Name=<nowiki>userIdColumnName</nowiki>|Description=<nowiki>The header name of the userId column</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>userNameMask</nowiki>|Description=<nowiki>The mask used to create new usernames - an advanced setting</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>generatePasswords</nowiki>|Description=<nowiki>OBSOLETE. Always false. Generate passwords during import</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importUserInfo</nowiki>|Description=<nowiki>Import or Update users</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importPhoneNumber</nowiki>|Description=<nowiki>Import or Update phonenumbers</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importAddress</nowiki>|Description=<nowiki>Import or Update addresses</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importPoints</nowiki>|Description=<nowiki>Import or Update points</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>importQualification</nowiki>|Description=<nowiki>Import or Update qualifications</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>parentResourceId</nowiki>|Description=<nowiki>Resource Id of the parent of the new users. Ignored if updating users</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=Dictionary|Name=<nowiki>mapping</nowiki>|Description=<nowiki>Mapping between header names and import names. If empty, automapping is used</nowiki>}} |
− | {{CGscriptMethods_Template|ReturnType=string|Name=Validate|Description=Same as Validate(true)}} | + | |Description=<nowiki>Set specific options for importing new users or altering existing users</nowiki>}} |
− | {{CGscriptMethods_Template|ReturnType=string|Name=Validate|Parameters= | + | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Inherited=object|Description=<nowiki>The string representation of the object.</nowiki>}} |
− | {{CGscriptParameters_Template|Type=bool|Name=errorOnSemiOpenQuestion|Description=Set to false if you need to import to questions with open parts and know that it may partially delete existing data}} | + | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>Validate</nowiki>|Description=<nowiki>Same as Validate(true)</nowiki>}} |
− | |Description=Validate prior to actual importing. Throws if errors, otherwise returns warning.}} | + | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>Validate</nowiki>|Parameters= |
+ | {{CGscriptParameters_Template|Type=bool|Name=<nowiki>errorOnSemiOpenQuestion</nowiki>|Description=<nowiki>Set to false if you need to import to questions with open parts and know that it may partially delete existing data</nowiki>}} | ||
+ | |Description=<nowiki>Validate prior to actual importing. Throws if errors, otherwise returns warning.</nowiki>}} | ||
|Properties= | |Properties= | ||
− | {{CGscriptProperties_Template|ReturnType=string|Name=ObjectTypeName|HasGetter=1|Description=The name of the type of object.}} | + | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Culture</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/set the culture used during import in case we don't want to use the logged-in-user's one (UseLoggedInUsersCultureDuringImport = false)</nowiki>}} |
− | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=TypeInformation|HasGetter=1|Description=Get information about this class.}} | + | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Language</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/set the language used when importing text</nowiki>}} |
− | {{CGscriptProperties_Template|ReturnType=bool|Name=UseLoggedInUsersCultureDuringImport|HasGetter=1|HasSetter=1|Description=Get/set if the culture used during import is the same as the logged in user or invariant culture. Default is invariant}} | + | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}} |
+ | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>UseLoggedInUsersCultureDuringImport</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/set if the culture used during import is the same as the logged in user or invariant culture. Default is invariant</nowiki>}} | ||
}} | }} | ||
Line 39: | Line 43: | ||
Bool advancedMode=false; | Bool advancedMode=false; | ||
number groupResourceId =0; | number groupResourceId =0; | ||
− | |||
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
− | |||
number qnaireRId = 15546533; | number qnaireRId = 15546533; | ||
number type=1; | number type=1; | ||
Line 52: | Line 54: | ||
</source> | </source> | ||
− | <br/><source lang="javascript"> | + | <br /><source lang="javascript"> |
//EX for import data to an existing answer sheet | //EX for import data to an existing answer sheet | ||
array Headers={"RPQId","Q2","Q4","Q5","TextValue","NumberValue"}; | array Headers={"RPQId","Q2","Q4","Q5","TextValue","NumberValue"}; | ||
Line 58: | Line 60: | ||
Bool advancedMode=false; | Bool advancedMode=false; | ||
number groupResourceId =0; | number groupResourceId =0; | ||
− | |||
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
− | |||
number qnaireRId = 15546533; | number qnaireRId = 15546533; | ||
number type=3; | number type=3; | ||
Line 71: | Line 71: | ||
</source> | </source> | ||
− | + | <br /><source lang="javascript"> | |
//EX for import new user info and phone number | //EX for import new user info and phone number | ||
array Headers={"First name","Last name","User_Email","Language","Culture","PhoneType_NotIdentified","User_CountryCode"}; | array Headers={"First name","Last name","User_Email","Language","Culture","PhoneType_NotIdentified","User_CountryCode"}; | ||
Line 77: | Line 77: | ||
Bool advancedMode=false; | Bool advancedMode=false; | ||
number groupResourceId =15548117; | number groupResourceId =15548117; | ||
− | |||
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
+ | string userIdColumnName=""; | ||
+ | string userNameMask=""; | ||
+ | bool generatePasswords=true; | ||
+ | bool importUserInfo = true; | ||
+ | bool importPhoneNumber = true; | ||
+ | bool importAddress=false; | ||
+ | bool importPoints =false; | ||
+ | bool importQualification=false; | ||
+ | number parentResourceId= 15546533; | ||
+ | Dictionary mapping = new Dictionary(); | ||
+ | iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping); | ||
+ | iM.Validate(); | ||
+ | iM.Import(); | ||
+ | </source> | ||
+ | <br /><source lang="javascript"> | ||
+ | //EX for importing new user and new qas | ||
+ | array Headers={"First name","Last name","User_Email","Language","Culture","PhoneType_NotIdentified","User_CountryCode","Q2","Q4","Q5","TextValue","NumberValue"}; | ||
+ | array Data={{"An","test2111_01","an@maysunshine.vn","da-DK","da-DK","12345678","dk",1,"q4",1,"Text1",1}}; | ||
+ | Bool advancedMode=false; | ||
+ | number groupResourceId =15548117; | ||
+ | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
+ | string userIdColumnName=""; | ||
+ | string userNameMask=""; | ||
+ | bool generatePasswords=true; | ||
+ | bool importUserInfo = true; | ||
+ | bool importPhoneNumber = true; | ||
+ | bool importAddress=false; | ||
+ | bool importPoints =false; | ||
+ | bool importQualification=false; | ||
+ | number parentResourceId= 15546533; | ||
+ | Dictionary mapping = new Dictionary(); | ||
+ | iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping); | ||
+ | number qnaireRId = 15546533; | ||
+ | number type=1; | ||
+ | string rpqIdColumnName=""; | ||
+ | bool isCommaSeparatedFormat = true; | ||
+ | //Dictionary mapping = new Dictionary(); | ||
+ | iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping); | ||
+ | iM.Validate(); | ||
+ | iM.Import(); | ||
+ | </source><br /><source lang="javascript"> | ||
+ | //Using SetDefaultNewUser | ||
+ | array Headers={"First name","Last name","User_Email"}; | ||
+ | array Data={{"An","test2211","an@maysunshine.vn"}}; | ||
+ | Bool advancedMode=false; | ||
+ | number groupResourceId =15548117; | ||
+ | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
string userIdColumnName=""; | string userIdColumnName=""; | ||
+ | string userNameMask=""; | ||
+ | bool generatePasswords=true; | ||
+ | bool importUserInfo = true; | ||
+ | bool importPhoneNumber = true; | ||
+ | bool importAddress=false; | ||
+ | bool importPoints =false; | ||
+ | bool importQualification=false; | ||
+ | number parentResourceId= 15546533; | ||
+ | Dictionary mapping = new Dictionary(); | ||
+ | iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping); | ||
+ | string languageIso="da-DK"; | ||
+ | string cultureIso="da-DK"; | ||
+ | string currency="USD"; | ||
+ | iM.SetDefaultNewUser(languageIso, cultureIso,currency ); | ||
+ | iM.Validate(); | ||
+ | iM.Import(); | ||
+ | |||
+ | </source><br /><source lang="javascript"> | ||
+ | //Update an existing user | ||
+ | array Headers={"userId","Language","Culture","Currency"}; | ||
+ | array Data={{"90414076","da-DK","da-DK","USD"}}; | ||
+ | Bool advancedMode=false; | ||
+ | number groupResourceId =15548117; | ||
+ | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
+ | string userIdColumnName="userId"; | ||
string userNameMask=""; | string userNameMask=""; | ||
bool generatePasswords=true; | bool generatePasswords=true; | ||
Line 90: | Line 161: | ||
number parentResourceId= 15546533; | number parentResourceId= 15546533; | ||
Dictionary mapping = new Dictionary(); | Dictionary mapping = new Dictionary(); | ||
− | + | iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping); | |
+ | iM.Validate(); | ||
+ | iM.Import(); | ||
+ | </source> | ||
+ | <br /><source lang="javascript"> | ||
+ | //update an existing qas by CustomerId (using SetDataImportOptions with type 4) | ||
+ | //CustomerID must be a text field, not numeric | ||
+ | array Headers={"CustomerID","Q1","Age"}; | ||
+ | array Data={{"AB123",2,1}}; | ||
+ | Bool advancedMode=false; | ||
+ | number groupResourceId =0; | ||
+ | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
+ | number qnaireRId = 15562388; | ||
+ | number type=4; | ||
+ | string idColumnName="CustomerID"; | ||
+ | bool isCommaSeparatedFormat = true; | ||
+ | Dictionary mapping = new Dictionary(); | ||
+ | iM.SetDataImportOptions(qnaireRId,type,idColumnName,isCommaSeparatedFormat,mapping); | ||
+ | iM.Validate(); | ||
+ | iM.Import(); | ||
+ | </source> | ||
− | + | <source lang="javascript"> | |
+ | //Set culture while import. If not set will use "." format, example: "45.967" | ||
+ | //Set Culture work combine with UseLoggedInUsersCultureDuringImport=false | ||
+ | array Headers={"qNumber"}; | ||
+ | array Data={{"45,967"}}; | ||
+ | Bool advancedMode=false; | ||
+ | number groupResourceId =0; | ||
+ | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
+ | number qnaireRId = 15636598; | ||
+ | number type=1; | ||
+ | string rpqIdColumnName=""; | ||
+ | bool isCommaSeparatedFormat = true; | ||
+ | Dictionary mapping = new Dictionary(); | ||
+ | //iM.UseLoggedInUsersCultureDuringImport=false; | ||
+ | iM.Culture = "da-DK"; | ||
+ | iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping); | ||
+ | iM.Validate(); | ||
+ | iM.Import(); | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //set language while import. If don't set, will use login user language | ||
+ | array Headers={"RPQ_StartDato","RPQ_SlutDato","RPQ_Status", "Q1"}; | ||
+ | array Data={{"2018-06-18 02:49:06","2018-06-18 02:51:44","Successfuldt interview", "1"}}; | ||
+ | Bool advancedMode=true; | ||
+ | number groupResourceId =0; | ||
+ | ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId); | ||
+ | number qnaireRId = 15636646; | ||
+ | number type=1; | ||
+ | string rpqIdColumnName=""; | ||
+ | bool isCommaSeparatedFormat = true; | ||
+ | Dictionary mapping = new Dictionary(); | ||
+ | iM.Language = "da-DK"; | ||
+ | iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping); | ||
iM.Validate(); | iM.Validate(); | ||
iM.Import(); | iM.Import(); | ||
</source> | </source> |
Latest revision as of 05:47, 2 July 2020
ImportManager
Import data and users.
Parent class
Inherits from object
Constructors
- (array Headers "A list of string that are the header names", array data "Data to import. An array of arrays of equal length as the headers", bool advancedMode "Enable setting advanced settings - Requires special navigation access", int groupResourceId "Group to add users to new users to and/or sample rule. Set to 0 to not add to group") - Make a new import with the given data
Methods
- array GetPossibleAutoMasForData() - Get default automaps. First value is column name, second is actual import field
- array GetPossibleAutoMasForUser() - Get default automaps. First value is column name, second is actual import field
- Dictionary Import() - Run the Import. Note that this will commit any pending changes
- Dictionary SetDataImportOptions(int projectQuestionnaireResourceId "The resource Id of where the data should be added/updated", int type "How to treat when already have existing answer sheets. 1 for Zero or One AnswerSheet, 2 for delete existing and create new, 3 for mapping to rpqIdColumnName", string idColumnName "Mapping for column name in case type is 3 or 4", bool isCommaSeparatedFormat "Import multi questions as comma separated format", Dictionary mapping "Mapping between header names and import names. If empty, automapping is used") - Set specific options for importing data or altering existing data
- Empty SetDefaultNewUser(string languageIso "Default language", string cultureIso "Default culture", string currency "Default currency") - Defaults for new users. If empty or not set, uses the global defaults
- Empty SetUserImportOptions(string userIdColumnName "The header name of the userId column", string userNameMask "The mask used to create new usernames - an advanced setting", bool generatePasswords "OBSOLETE. Always false. Generate passwords during import", bool importUserInfo "Import or Update users", bool importPhoneNumber "Import or Update phonenumbers", bool importAddress "Import or Update addresses", bool importPoints "Import or Update points", bool importQualification "Import or Update qualifications", array permissions "Determine which groups should have access to the new users", Dictionary mapping "Mapping between header names and import names. If empty, automapping is used") - OBSOLETE. Use the new overload with parentResourceId.
- Dictionary SetUserImportOptions(string userIdColumnName "The header name of the userId column", string userNameMask "The mask used to create new usernames - an advanced setting", bool generatePasswords "OBSOLETE. Always false. Generate passwords during import", bool importUserInfo "Import or Update users", bool importPhoneNumber "Import or Update phonenumbers", bool importAddress "Import or Update addresses", bool importPoints "Import or Update points", bool importQualification "Import or Update qualifications", int parentResourceId "Resource Id of the parent of the new users. Ignored if updating users", Dictionary mapping "Mapping between header names and import names. If empty, automapping is used") - Set specific options for importing new users or altering existing users
- (From object) string ToString() - The string representation of the object.
- string Validate() - Same as Validate(true)
- string Validate(bool errorOnSemiOpenQuestion "Set to false if you need to import to questions with open parts and know that it may partially delete existing data") - Validate prior to actual importing. Throws if errors, otherwise returns warning.
Properties
- string Culture { get; set; } - Get/set the culture used during import in case we don't want to use the logged-in-user's one (UseLoggedInUsersCultureDuringImport = false)
- string Language { get; set; } - Get/set the language used when importing text
- string ObjectTypeName { get; } - The name of the type of object.
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
- bool UseLoggedInUsersCultureDuringImport { get; set; } - Get/set if the culture used during import is the same as the logged in user or invariant culture. Default is invariant
Examples
// EX for making import qnaire data without user (acreate new qas with no user)
array Headers={"Q2","Q4","Q5","TextValue","NumberValue"};
array Data={{1,"q4",1,"Text1",1}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15546533;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();
//EX for import data to an existing answer sheet
array Headers={"RPQId","Q2","Q4","Q5","TextValue","NumberValue"};
array Data={{1742872963,1,"q4",1,"Text1",1}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15546533;
number type=3;
string rpqIdColumnName="RPQId";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();
//EX for import new user info and phone number
array Headers={"First name","Last name","User_Email","Language","Culture","PhoneType_NotIdentified","User_CountryCode"};
array Data={{"An","test","an@maysunshine.vn","da-DK","da-DK","12345678","dk"}};
Bool advancedMode=false;
number groupResourceId =15548117;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
string userIdColumnName="";
string userNameMask="";
bool generatePasswords=true;
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary();
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
iM.Validate();
iM.Import();
//EX for importing new user and new qas
array Headers={"First name","Last name","User_Email","Language","Culture","PhoneType_NotIdentified","User_CountryCode","Q2","Q4","Q5","TextValue","NumberValue"};
array Data={{"An","test2111_01","an@maysunshine.vn","da-DK","da-DK","12345678","dk",1,"q4",1,"Text1",1}};
Bool advancedMode=false;
number groupResourceId =15548117;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
string userIdColumnName="";
string userNameMask="";
bool generatePasswords=true;
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary();
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
number qnaireRId = 15546533;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
//Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();
//Using SetDefaultNewUser
array Headers={"First name","Last name","User_Email"};
array Data={{"An","test2211","an@maysunshine.vn"}};
Bool advancedMode=false;
number groupResourceId =15548117;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
string userIdColumnName="";
string userNameMask="";
bool generatePasswords=true;
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary();
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
string languageIso="da-DK";
string cultureIso="da-DK";
string currency="USD";
iM.SetDefaultNewUser(languageIso, cultureIso,currency );
iM.Validate();
iM.Import();
//Update an existing user
array Headers={"userId","Language","Culture","Currency"};
array Data={{"90414076","da-DK","da-DK","USD"}};
Bool advancedMode=false;
number groupResourceId =15548117;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
string userIdColumnName="userId";
string userNameMask="";
bool generatePasswords=true;
bool importUserInfo = true;
bool importPhoneNumber = true;
bool importAddress=false;
bool importPoints =false;
bool importQualification=false;
number parentResourceId= 15546533;
Dictionary mapping = new Dictionary();
iM.SetUserImportOptions(userIdColumnName,userNameMask,generatePasswords,importUserInfo,importPhoneNumber,importAddress,importPoints,importQualification,parentResourceId,mapping);
iM.Validate();
iM.Import();
//update an existing qas by CustomerId (using SetDataImportOptions with type 4)
//CustomerID must be a text field, not numeric
array Headers={"CustomerID","Q1","Age"};
array Data={{"AB123",2,1}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15562388;
number type=4;
string idColumnName="CustomerID";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.SetDataImportOptions(qnaireRId,type,idColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();
//Set culture while import. If not set will use "." format, example: "45.967"
//Set Culture work combine with UseLoggedInUsersCultureDuringImport=false
array Headers={"qNumber"};
array Data={{"45,967"}};
Bool advancedMode=false;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15636598;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
//iM.UseLoggedInUsersCultureDuringImport=false;
iM.Culture = "da-DK";
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();
//set language while import. If don't set, will use login user language
array Headers={"RPQ_StartDato","RPQ_SlutDato","RPQ_Status", "Q1"};
array Data={{"2018-06-18 02:49:06","2018-06-18 02:51:44","Successfuldt interview", "1"}};
Bool advancedMode=true;
number groupResourceId =0;
ImportManager iM = new ImportManager (Headers, Data, advancedMode, groupResourceId);
number qnaireRId = 15636646;
number type=1;
string rpqIdColumnName="";
bool isCommaSeparatedFormat = true;
Dictionary mapping = new Dictionary();
iM.Language = "da-DK";
iM.SetDataImportOptions(qnaireRId,type,rpqIdColumnName,isCommaSeparatedFormat,mapping);
iM.Validate();
iM.Import();