diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod index b956bffb576efb783f9ab6736572b1c02e70ef10..cba3010100ed198c433c1a2f516d8a2bd7e7ed8c 100644 --- a/entity/Offer_entity/Offer_entity.aod +++ b/entity/Offer_entity/Offer_entity.aod @@ -203,6 +203,7 @@ <entityField> <name>OFFER_ID</name> <documentation>%aditoprj%/entity/Offer_entity/entityfields/offer_id/documentation.adoc</documentation> + <valueProcess>%aditoprj%/entity/Offer_entity/entityfields/offer_id/valueProcess.js</valueProcess> </entityField> <entityFieldGroup> <name>OfferCode_VersNr_fieldgroup</name> @@ -319,6 +320,7 @@ <description></description> <contentType>LONG_TEXT</contentType> <mandatory v="true" /> + <valueProcess>%aditoprj%/entity/Offer_entity/entityfields/address/valueProcess.js</valueProcess> </entityField> <entityField> <name>ChosenAddress</name> @@ -451,6 +453,27 @@ <mandatory v="false" /> <description>PARAMETER</description> </entityParameter> + <entityParameter> + <name>OfferAddress_param</name> + <expose v="true" /> + <triggerRecalculation v="true" /> + <mandatory v="false" /> + <description>PARAMETER</description> + </entityParameter> + <entityParameter> + <name>OfferCode_param</name> + <expose v="true" /> + <triggerRecalculation v="true" /> + <mandatory v="false" /> + <description>PARAMETER</description> + </entityParameter> + <entityParameter> + <name>OfferVersnr_param</name> + <expose v="true" /> + <triggerRecalculation v="true" /> + <mandatory v="false" /> + <description>PARAMETER</description> + </entityParameter> </entityFields> <recordContainers> <dbRecordContainer> diff --git a/entity/Offer_entity/entityfields/address/valueProcess.js b/entity/Offer_entity/entityfields/address/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..160f9518edab8b5ed593d921661aada906512ee4 --- /dev/null +++ b/entity/Offer_entity/entityfields/address/valueProcess.js @@ -0,0 +1,7 @@ +import("system.result"); +import("system.vars"); + +if (vars.exists("$param.OfferAddress_param")) +{ + result.string(vars.get("$param.OfferAddress_param")); +} \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/currency/displayValueProcess.js b/entity/Offer_entity/entityfields/currency/displayValueProcess.js index 0b37c8e45066e2587bafc2bd49cc082dc93708fa..251895de0caa384e595ac12282df6a3955093b04 100644 --- a/entity/Offer_entity/entityfields/currency/displayValueProcess.js +++ b/entity/Offer_entity/entityfields/currency/displayValueProcess.js @@ -2,7 +2,7 @@ import("system.result"); import("system.vars"); import("Keyword_lib"); -if (vars.exists("$param.OfferCurrency_param")) +if (vars.exists("$param.OfferCurrency_param") && vars.get("$param.OfferCurrency_param")) { var currency = KeywordUtils.getViewValue($KeywordRegistry.get.Currency, vars.get("$param.OfferCurrency_param")); result.string(currency); diff --git a/entity/Offer_entity/entityfields/currency/valueProcess.js b/entity/Offer_entity/entityfields/currency/valueProcess.js index 260f47d1333b2321baf8b73ef26d2adc0cf98296..636be1adc9a7505eea4d957860d46a81856f5a93 100644 --- a/entity/Offer_entity/entityfields/currency/valueProcess.js +++ b/entity/Offer_entity/entityfields/currency/valueProcess.js @@ -1,7 +1,7 @@ import("system.result"); import("system.vars"); -if (vars.exists("$param.OfferCurrency_param")) +if (vars.exists("$param.OfferCurrency_param") && vars.get("$param.OfferCurrency_param")) { result.string(vars.get("$param.OfferCurrency_param")); } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/header/valueProcess.js b/entity/Offer_entity/entityfields/header/valueProcess.js index 6dcb1ead4d2d55e67ca53a852b3147e4d824e5e4..c1dd2bbc6e368ccd25f363f47e8e86f6abceaa55 100644 --- a/entity/Offer_entity/entityfields/header/valueProcess.js +++ b/entity/Offer_entity/entityfields/header/valueProcess.js @@ -1,7 +1,7 @@ import("system.result"); import("system.vars"); -if (vars.exists("$param.OfferHeader_param")) +if (vars.exists("$param.OfferHeader_param") && vars.get("$param.OfferHeader_param")) { result.string(vars.get("$param.OfferHeader_param")); } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/language/displayValueProcess.js b/entity/Offer_entity/entityfields/language/displayValueProcess.js index a9f344b0eee36eda5b2105a837fe5f33f3dca16e..987df7556fbe55afa0152a52e1e8d4c766b4ce39 100644 --- a/entity/Offer_entity/entityfields/language/displayValueProcess.js +++ b/entity/Offer_entity/entityfields/language/displayValueProcess.js @@ -4,7 +4,7 @@ import("system.result"); import("system.vars"); import("Sql_lib"); -if (vars.exists("$param.OfferLanguage_param")) +if (vars.exists("$param.OfferLanguage_param") && vars.get("$param.OfferLanguage_param")) { var iso3 = vars.get("$param.OfferLanguage_param"); var latinName = db.cell(SqlCondition.begin() diff --git a/entity/Offer_entity/entityfields/language/valueProcess.js b/entity/Offer_entity/entityfields/language/valueProcess.js index 7bb63ab86be46e325331015bb4949f484049dbad..4fc924e18219f6a6b30f4b3ebb8ffb22d8ed3cb0 100644 --- a/entity/Offer_entity/entityfields/language/valueProcess.js +++ b/entity/Offer_entity/entityfields/language/valueProcess.js @@ -1,7 +1,7 @@ import("system.result"); import("system.vars"); -if (vars.exists("$param.OfferLanguage_param")) +if (vars.exists("$param.OfferLanguage_param") && vars.get("$param.OfferLanguage_param")) { result.string(vars.get("$param.OfferLanguage_param")); } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js b/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js index 0a83f6827223845ef954c036bf5d99866118fe5e..add48fbf11814bdf125f71afc331b9957afa4172 100644 --- a/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js +++ b/entity/Offer_entity/entityfields/newofferversion/onActionProcess.js @@ -1,26 +1,16 @@ import("system.vars"); import("system.neon"); -import("Util_lib"); -import("Neon_lib"); import("Offer_lib"); -var InputMapping = { - - "OFFER": { - condition: "OFFERID = '" + vars.get("$field.OFFERID") + "'" - , ValueMapping: { - "OFFER_ID": vars.get("$field.OFFERID") - , "OFFERCODE": vars.get("$field.OFFERCODE") - , "VERSNR": OfferUtils.getNextOfferVersionNumber(vars.get("$field.OFFERCODE")) - } - , SubModules:{ - "OFFERITEM": { - condition: "OFFER_ID = '" + vars.get("$field.OFFERID") + "' order by ITEMSORT" - } - } - } +var params = { + "ContactId_param" : vars.get("$field.CONTACT_ID"), + "SalesprojectId_param" : vars.get("$field.SALESPROJECT_ID"), + "OfferLanguage_param" : vars.get("$field.LANGUAGE"), + "OfferOriginal_Id_param" : vars.get("$field.OFFERID"), + "OfferCode_param" : vars.get("$field.OFFERCODE"), + "OfferVersnr_param" : OfferUtils.getNextOfferVersionNumber(vars.get("$field.OFFERCODE")), + "OfferCurrency_param" : vars.get("$field.CURRENCY"), + "OfferAddress_param" : vars.get("$field.ADDRESS"), + "OfferHeader_param" : vars.get("$field.HEADER") } - -var ModulesMapping = CopyModuleUtils.copyModule(InputMapping); - -CopyModuleUtils.openNewModules("Offer", ModulesMapping); \ No newline at end of file +neon.openContext("Offer", null, null, neon.OPERATINGSTATE_NEW, params); \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/offer_id/valueProcess.js b/entity/Offer_entity/entityfields/offer_id/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/entity/Offer_entity/entityfields/offercode/onValidation.js b/entity/Offer_entity/entityfields/offercode/onValidation.js index de949a3e766bbf81de26ee22689c4808a7faae44..3b9c0b76f65fa2b8ae4026d17b1e78d5197d919f 100644 --- a/entity/Offer_entity/entityfields/offercode/onValidation.js +++ b/entity/Offer_entity/entityfields/offercode/onValidation.js @@ -6,7 +6,8 @@ import("Salesproject_lib"); import("Util_lib"); import("Entity_lib"); -if( vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW +if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW + && !vars.exists("$param.OfferCode_param") && !OfferUtils.validateOfferNumber(ProcessHandlingUtils.getOnValidationValue(vars.get("$field.OFFERCODE"))) ) { vars.set( "$field.OFFERCODE", OfferUtils.getNextOfferNumber().toString() ); diff --git a/entity/Offer_entity/entityfields/offercode/valueProcess.js b/entity/Offer_entity/entityfields/offercode/valueProcess.js index 933257e8cc871bfd2d5cb0be92049e55ea93a2b8..502b44731b281c7fc79094de58242869d07e423d 100644 --- a/entity/Offer_entity/entityfields/offercode/valueProcess.js +++ b/entity/Offer_entity/entityfields/offercode/valueProcess.js @@ -4,6 +4,9 @@ import("system.neon"); import("Offer_lib"); if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) -{ - result.string(OfferUtils.getNextOfferNumber()); +{ + if (vars.exists("$param.OfferCode_param") && vars.get("$param.OfferCode_param")) + result.string(vars.get("$param.OfferCode_param")); + else + result.string(OfferUtils.getNextOfferNumber()); } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/versnr/valueProcess.js b/entity/Offer_entity/entityfields/versnr/valueProcess.js index f3ad73d05605a0009779e02d2767edba66fe2189..5d3797b77b0fc1e83590585de35fa636da9962aa 100644 --- a/entity/Offer_entity/entityfields/versnr/valueProcess.js +++ b/entity/Offer_entity/entityfields/versnr/valueProcess.js @@ -5,5 +5,8 @@ import("Offer_lib"); if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) { - result.string( "1" ); + if (vars.exists("$param.OfferVersnr_param") && vars.get("$param.OfferVersnr_param")) + result.string(vars.get("$param.OfferVersnr_param")); + else + result.string( "1" ); } \ No newline at end of file diff --git a/entity/Offer_entity/recordcontainers/db/onDBInsert.js b/entity/Offer_entity/recordcontainers/db/onDBInsert.js index 5630d92a293638146ad1cc8fdfa7e9a480ce1b81..6b3c4033a05890bdd874ce4fa610333b06fdc538 100644 --- a/entity/Offer_entity/recordcontainers/db/onDBInsert.js +++ b/entity/Offer_entity/recordcontainers/db/onDBInsert.js @@ -3,4 +3,4 @@ import("system.vars"); import("Offer_lib"); if (vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW && vars.exists("$param.OfferOriginal_Id_param")) - OfferUtils.copyOfferItems(vars.getString("$param.OfferOriginal_Id_param"), vars.get("$field.OFFERID")); \ No newline at end of file + OfferUtils.copyOfferItems(vars.getString("$param.OfferOriginal_Id_param"), vars.get("$field.OFFERID")); diff --git a/neonView/AttributePreview_view/AttributePreview_view.aod b/neonView/AttributePreview_view/AttributePreview_view.aod index 59adbab341fa443a18be81de0097635898b4fc31..f3e5d5fa9e51b0d3fedf0e8f0b07f37f8c561472 100644 --- a/neonView/AttributePreview_view/AttributePreview_view.aod +++ b/neonView/AttributePreview_view/AttributePreview_view.aod @@ -20,6 +20,10 @@ <entityField>#ENTITY</entityField> <title></title> <fields> + <entityFieldLink> + <name>5f20a5d4-0343-4b8c-92bf-15eeb2483ba9</name> + <entityField>ATTRIBUTE_PARENT_ID</entityField> + </entityFieldLink> <entityFieldLink> <name>e00bfeb1-7003-4d5a-b71a-c6921e255c9d</name> <entityField>ATTRIBUTE_ACTIVE</entityField> diff --git a/others/guide/how to copy objects with subitems.adoc b/others/guide/how to copy objects with subitems.adoc new file mode 100644 index 0000000000000000000000000000000000000000..63f85af69459e163f28844400e364f42d7ca8023 --- /dev/null +++ b/others/guide/how to copy objects with subitems.adoc @@ -0,0 +1,100 @@ +How to make an action for copying modules +========================================= +:toc2: left +:numbered: + +== What this guide is for == +You want to create an action or process that should copy a module with +related sub-items. +(for example: Offer + OfferItems, Order + OrderItems) + +== How to do it == +There are two possibilities when it comes to creating a new dataset based on another one: + +* Save it directly and open the created dataset in show-mode +* Open it in new-mode so that the user can make changes first or cancel the action + +=== Save it directly === +This is relatively easy to do with the functions in the Neon_lib. +At first you have make the copy with the method "CopyModuleUtils.copyModule". It requires an InputMapping object that +defines the structure of the module. For example: + +[source, javascript] +---- +var InputMapping = { + "OFFER": { + condition: "OFFERID = '" + vars.get("$field.OFFERID") + "'" + , ValueMapping: { + "OFFER_ID": "" + , "OFFERCODE": OfferUtils.getNextOfferNumber() + , "VERSNR": "1" + } + , SubModules:{ + "OFFERITEM": { + condition: "OFFER_ID = '" + vars.get("$field.OFFERID") + "' order by ITEMSORT" + } + } + } +} +---- + +The root element of the object (in this case 'OFFER') defines what module is copied, the condition is used to select the specific dataset. +'ValueMapping' should be used when some fields need new values (for example the offercode should not be the same as in the copied object). +You can also set 'SubModules' in order to copy sub-elements like offerItems. +Now you just have to use the following code: + +[source, javascript] +---- +var ModulesMapping = CopyModuleUtils.copyModule(InputMapping); + +CopyModuleUtils.openNewModules("Offer", ModulesMapping); +---- + +The first line copies the module and the second line opens the newly created dataset. + +=== Open it in new-mode first === +For this case it needs a few more steps. For values that should be preset in the edit view, you will need to create +parameters in the entity for every one (set them exposed, triggerRecalculation and not mandatory). After that you have to use these parameters in the valueProcess of the fields +they should fill. +The next step is to create an action that opens the context in new-mode. That could look like this: + +[source, javascript] +---- +var params = { + "ContactId_param" : vars.get("$field.CONTACT_ID"), + "SalesprojectId_param" : vars.get("$field.SALESPROJECT_ID"), + "OfferLanguage_param" : vars.get("$field.LANGUAGE"), + "OfferOriginal_Id_param" : vars.get("$field.OFFERID"), + "OfferCode_param" : vars.get("$field.OFFERCODE"), + "OfferVersnr_param" : OfferUtils.getNextOfferVersionNumber(vars.get("$field.OFFERCODE")), + "OfferCurrency_param" : vars.get("$field.CURRENCY"), + "OfferAddress_param" : vars.get("$field.ADDRESS"), + "OfferHeader_param" : vars.get("$field.HEADER") +} +neon.openContext("Offer", null, null, neon.OPERATINGSTATE_NEW, params); +---- + +Important: There has to be one parameter for the id, so that sub-items can be copied (see the following). + +Now we can preset values of the module, but what about related things like offerItems? +For that we use the same function as in the section above. Because the offerItems should only be copied to the new offer when the user +saved it, this has to be done in the onInsert-process of the recordcontainer. + +[source, javascript] +---- +if (vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW && vars.exists("$param.OfferOriginal_Id_param")) +{ + var InputMapping = { + "OFFERITEM": { + condition: "OFFER_ID = '" + vars.getString("$param.OfferOriginal_Id_param") + "' order by ITEMSORT", + ValueMapping: { + "OFFER_ID" : vars.get("$field.OFFERID") + } + } + }; + CopyModuleUtils.copyModule(InputMapping); +} +---- + +The offer is already created, so that only offerItem is needed in the 'InputMapping'. The 'condition' should use the id of the offer +that is copied and in 'ValueMapping' the foreign-key 'OFFER_ID' gets the value of the id of the newly created offer. \ No newline at end of file