Start service from service
Last updated
Was this helpful?
Last updated
Was this helpful?
Het aanmaken van een service via een action form, gekoppeld aan een service. Bij aanmaak van de nieuwe service willen we:
- Data overzetten van de bron-service
- De relatie leggen tussen de bron-service en de nieuw-aangemaakte service.
Setup:
- Voorzie een formulier waarin de GUID van de bron-service wordt getoond, alsook een keuze van template voor de nieuwe service.
Naamgeving:
- Bronservice: mother
- Aan te maken service: child
Een voorbeeld vind je hier:
DEV SMTX: https://dev.ssp7.smt-x.com/Forms/Admin/formDetail.aspx?id=726
General Settings
- Allow default values via URL
- On submit: Execute Javascript block
- Extra interface(s) : ServiceCatalogInterface
- In het vakje ‘Script’ komt dan de JS – zie verder in dit document.
Benodigde velden:
- Field met internal label ‘serviceguid’ die de GUID bevat
o Hier hoeft geen default value in te komen, we vullen die via de URL
- Field met internal label ‘ChildSelection’ die de naam van de template geeft
o In dit geval: Demo Template from Template - Amendement onderzoek
o Dit is nu een read-only display field, maar kan perfect een dropdown zijn met meerdere templates. Let wel dat de target fields gelijk moeten zijn. Indien ze verschillend zijn, zal je een ander formulier moeten aanmaken, omdat de JS verschillend is.
The code below nos supports transferring custom actor, a few examples are entered.
--------------------
var forminstance = JSON.parse(g_forminstance_string);
var externalprovidername = "ServiceCatalogWriter";
var externalproviderkey = "i-can-write";
var actorperson = forminstance.requestedforpersonid;
//currently no language dependent fields are supported
// Below are the fields to be copied
var fieldstocopy = [
{ sourcename: "Study_number", targetname: "Study_number" },
{ sourcename: "Full_study_title", targetname: "Full_study_title" },
{ sourcename: "Department_PI", targetname: "Department_PI" },
{ sourcename: "STU_CEC", targetname: "Amend_CEC" },
{ sourcename: "Acronym", targetname: "Acronym" },
];
// below are
var customactorstocopy = [
{ sourcename: "Principal_Investigator", targetname: "Principal_Investigator" },
{ sourcename: "Subinvestigators", targetname: "Subinvestigators" },
{ sourcename: "Study_Team_Members", targetname: "Study_Team_Members" },
{ sourcename: "Sponsor_submission", targetname: "Sponsor_submission" },
{ sourcename: "Sponsor_contract", targetname: "Sponsor_contract" },
{ sourcename: "Students", targetname: "Students" },
];
var templateselections = forminstance.values.filter(function (v) { return v.internallabel === "ChildSelection"; });
var sourceserviceguids = forminstance.values.filter(function (v) { return v.internallabel === "serviceguid"; });
if (templateselections.length === 1 && sourceserviceguids.length === 1) {
var newservicetemplatename = templateselections[0].value;
var sourceserviceguid = sourceserviceguids[0].value;
if (newservicetemplatename && sourceserviceguid) {
var sourceservice = JSON.parse(ServiceCatalogInterface.getServiceDetail(sourceserviceguid, { PartsUseValue: true, PartsAsFlatList: true, LoadRelations: false }));
if (sourceservice) {
var newserviceguid = CommonInterface.newGuid();
//set the template of the service, this creates the service too
var result = CommonInterface.callWebservice("Services: update service field", { ServiceGuid: newserviceguid, FieldName: "template", ActorPerson: actorperson, Text: newservicetemplatename, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
if (result === "OK") {
var errors = [];
//add relation
result = CommonInterface.callWebservice("Services: add relation", { ParentServiceGuid: sourceserviceguid, ChildServiceGuid: newserviceguid, ActorPerson: actorperson, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
if (result !== "OK") {
errors.push("Failed to add relation: " + result);
}
//copy fields
fieldstocopy.forEach(function (fieldtocopy) {
var sourcefields = sourceservice.parts.filter(function (part) { return part.internalname === fieldtocopy.sourcename; });
if (sourcefields.length > 0) {
var sourcefield = sourcefields[0];
//only copy when there's a value, makes no sense if empty
if (sourcefield.value) {
if (fieldtocopy.fieldtype === "numeric") {
result = CommonInterface.callWebservice("Services: update template part numeric value", { ServiceGuid: newserviceguid, InternalName: fieldtocopy.targetname, ActorPerson: actorperson, Numeric: sourcefield.value, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
} else if (fieldtocopy.fieldtype === "datetime") {
result = CommonInterface.callWebservice("Services: update template part datetime value", { ServiceGuid: newserviceguid, InternalName: fieldtocopy.targetname, ActorPerson: actorperson, DateTime: sourcefield.value, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
} else {
result = CommonInterface.callWebservice("Services: update template part text value", { ServiceGuid: newserviceguid, InternalName: fieldtocopy.targetname, ActorPerson: actorperson, Text: sourcefield.value, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
}
if (result !== "OK") {
errors.push("Failed to set field " + fieldtocopy.targetname + ": " + result);
}
}
} else {
//field not found
errors.push("Field " + fieldtocopy.sourcename + " not found in source service");
}
});
//copy actors
customactorstocopy.forEach(function (customactortocopy) {
var sourcecustomactors = sourceservice.customactors.filter(function (customactor) { return customactor.internalname === customactortocopy.sourcename; });
if (sourcecustomactors.length > 0) {
var sourcecustomactor = sourcecustomactors[0];
//only copy when there's a value, makes no sense if empty
if (sourcecustomactor.value) {
var ismultiple = sourcecustomactor.typename === "Multiple_persons" || sourcecustomactor.typename === "Multiple_person_groups";
var ispersongroup = sourcecustomactor.typename === "Single_person_group" || sourcecustomactor.typename === "Multiple_person_groups";
if (ismultiple) {
//value is array of person or persongroup
if (Array.isArray(sourcecustomactor.value)) {
sourcecustomactor.value.forEach(function (personorpersongroup) {
if (personorpersongroup) {
//need to call the Services: add person to service person list or Services: add persongroup to service persongroup list
if (ispersongroup) {
result = CommonInterface.callWebservice("Services: add persongroup to service persongroup list", { ServiceGuid: newserviceguid, TypeName: "CustomActor", CustomActorInternalName: customactortocopy.targetname, ActorPerson: actorperson, PersonGroup: personorpersongroup.id, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
} else {
result = CommonInterface.callWebservice("Services: add person to service person list", { ServiceGuid: newserviceguid, TypeName: "CustomActor", CustomActorInternalName: customactortocopy.targetname, ActorPerson: actorperson, Person: personorpersongroup.id, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
}
if (result !== "OK") {
errors.push("Failed to add custom actor " + customactortocopy.targetname + ": " + result);
}
}
});
} else {
errors.push("Failed to set custom actor " + customactortocopy.targetname + ": value is not an array");
}
} else {
//value is person or persongroup
//need to call the Services: save custom actor person to service or Services: save custom actor person group to service
if (ispersongroup) {
result = CommonInterface.callWebservice("Services: save custom actor person group to service", { ServiceGuid: newserviceguid, CustomActorInternalName: customactortocopy.targetname, ActorPerson: actorperson, PersonGroup: sourcecustomactor.value.id, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
} else {
result = CommonInterface.callWebservice("Services: save custom actor person to service", { ServiceGuid: newserviceguid, CustomActorInternalName: customactortocopy.targetname, ActorPerson: actorperson, Person: sourcecustomactor.value.id, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
}
if (result !== "OK") {
errors.push("Failed to set custom actor " + customactortocopy.targetname + ": " + result);
}
}
}
} else {
//custom actor not found
errors.push("Custom actor " + customactortocopy.sourcename + " not found in source service");
}
});
var toreturn = "Amendment created, <a href='" + CommonInterface.getSspUrl() + "/ServiceCatalog/Admin/ServiceAddEdit.aspx?genericguid=" + newserviceguid + "' target='_top'>click here to access the new amendment.</a>";
if (errors.length) {
toreturn += "<br />Attention, errors occured:<ul>" + errors.map(function (er) { return "<li>" + CommonInterface.htmlEncode(er) + "</li>"; }).join("") + "</ul>";
}
return toreturn;
} else {
return "Creation of service failed: " + result;
}
} else {
return "Source service not found";
}
} else {
return "One or more form fields are empty";
}
} else {
return "One or more form fields not found";
}
In de code hoef je enkel de gele teksten aan te passen. Deze omvatten de over te zetten velden en het bericht met de link na aanmaak van de nieuwe service. De guid & aan te maken template komen uit het formulier.
Start code:
var forminstance = JSON.parse(g_forminstance_string);
var externalprovidername = "ServiceCatalogAPI";
var externalproviderkey = "50bK3v3b59coDb@ZZjF#sTFaE8c7iR&n";
var actorperson = forminstance.requestedforpersonid;
//currently no language dependent fields are supported
var fieldstocopy = [
{ sourcename: "study_title", targetname: "study_title" },
{ sourcename: "st_title_ENG", targetname: "st_title_ENG" },
{ sourcename: "aanvraag_acacom", targetname: "aanvraag_acacom" },
];
//hier bepalen we via de internal labels welke de bron en doelvelden zijn – sourcename is de bron, targetname is in de aan te maken service
var templateselections = forminstance.values.filter(function (v) { return v.internallabel === "ChildSelection"; });
//Declaratie van het internal label van het veld in het formulier waarin de template van de aan te maken service wordt gekozen
var sourceserviceguids = forminstance.values.filter(function (v) { return v.internallabel === "serviceguid"; });
//Declaratie van het internal label van het veld in het formulier waarin de GUID van de bron-service wordt meegegeven
if (templateselections.length === 1 && sourceserviceguids.length === 1) {
var newservicetemplatename = templateselections[0].value;
var sourceserviceguid = sourceserviceguids[0].value;
if (newservicetemplatename && sourceserviceguid) {
var sourceservice = JSON.parse(ServiceCatalogInterface.getServiceDetail(sourceserviceguid, { PartsUseValue: true, PartsAsFlatList: true, LoadRelations: false }));
if (sourceservice) {
var newserviceguid = CommonInterface.newGuid();
//set the template of the service, this creates the service too
var result = CommonInterface.callWebservice("Services: update service field", { ServiceGuid: newserviceguid, FieldName: "template", ActorPerson: actorperson, Text: newservicetemplatename, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
if (result === "OK") {
var errors = [];
//add relation
result = CommonInterface.callWebservice("Services: add relation", { ParentServiceGuid: sourceserviceguid, ChildServiceGuid: newserviceguid, ActorPerson: actorperson, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
if (result !== "OK") {
errors.push("Failed to add relation: " + result);
}
//copy fields
fieldstocopy.forEach(function (fieldtocopy) {
var sourcefields = sourceservice.parts.filter(function (part) { return part.internalname === fieldtocopy.sourcename; });
if (sourcefields.length > 0) {
var sourcefield = sourcefields[0];
//only copy when there's a value, makes no sense if empty
if (sourcefield.value) {
if (fieldtocopy.fieldtype === "numeric") {
result = CommonInterface.callWebservice("Services: update template part numeric value", { ServiceGuid: newserviceguid, InternalName: fieldtocopy.targetname, ActorPerson: actorperson, Numeric: sourcefield.value, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
} else if (fieldtocopy.fieldtype === "datetime") {
result = CommonInterface.callWebservice("Services: update template part datetime value", { ServiceGuid: newserviceguid, InternalName: fieldtocopy.targetname, ActorPerson: actorperson, DateTime: sourcefield.value, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
} else {
result = CommonInterface.callWebservice("Services: update template part text value", { ServiceGuid: newserviceguid, InternalName: fieldtocopy.targetname, ActorPerson: actorperson, Text: sourcefield.value, ProviderName: externalprovidername, SecurityCheck: externalproviderkey });
}
if (result !== "OK") {
errors.push("Failed to set field " + fieldtocopy.targetname + ": " + result);
}
}
} else {
//field not found
errors.push("Field " + fieldtocopy.sourcename + " not found in source service");
}
});
var toreturn = "Item aangemaakt, <a href='" + CommonInterface.getSspUrl() + "/ServiceCatalog/Admin/ServiceAddEdit.aspx?genericguid=" + newserviceguid + "' target='_top'>klik hier om er naartoe te gaan.</a>";
// Hierboven staat de tekst die de gebruiker ziet na aanmaak van de nieuwe service. Deze bevat ook de link om erheen te gaan. Deze link is omgeving-onafhankelijk.
if (errors.length) {
toreturn += "<br />Opgepast, er waren enkele problemen:<ul>" + errors.map(function (er) { return "<li>" + CommonInterface.htmlEncode(er) + "</li>"; }).join("") + "</ul>";
}
return toreturn;
} else {
return "Creation of service failed: " + result;
}
} else {
return "Source service not found";
}
} else {
return "One or more form fields are empty";
}
} else {
return "One or more form fields not found";
}
Koppel het Action form aan de moeder-template.
In dit geval : Demo Template from template - Algemeen onderzoek
Welke velden zet ik over:
Bron
Int. label
Type
Target Int. label
Dutch title of the study
study_title
Multiple text lines
study_title
English title of the study
st_title_ENG
Multiple text lines
st_title_ENG
I wish to submit an application concerning
aanvraag_acacom
radio
aanvraag_acacom