Hi everyone,
id designed a custom extension with a new field that represents the creator of the ticket.
What I'd to do further, is to set the default value of the field as the logged in user. Therefore i'm usering the <method> tag. The final goal should be to set the "creator" as ":current_contact_id".</method>
My method is defined as this (it belongs to the class "Ticket"),
<methods><methodid="cus_set_creator_to_current_user"_delta="define"><comment>//Custom: set the value for the custom designed field 'cust_ticket_creator_id' to the id of the currently logged in user</comment><static>true</static><access>public</access><type>Overload-DBObject</type><code><![CDATA[ public function cus_set_creator_to_current_user() { $this->Set('cust_ticket_creator_id', 4); return true; }]]></code></method></methods>
... i nearly made it working, there was a missunderstanding, i have to declare the function as 'ComputeValues'
Still open: when i define a fixed Value like
$this->SetIfNull('cust_ticket_creator_id', '4');
but it does not work with:
$this->SetIfNull('cust_ticket_creator_id', $this->current_contact_id);
<methods><methodid="cus_set_creator_to_current_user"_delta="define"><comment></comment><static>false</static><access>public</access><type>Overload-DBObject</type><code><![CDATA[ public function **ComputeValues()** { $this->SetIfNull('cust_ticket_creator_id', $this->current_contact_id); return true; }]]></code></method></methods>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
that leads to an error during setup:
Parse error: syntax error, unexpected '$', expecting ')' in C:\inetpub\itopdemo\env-production\itop-tickets\model.itop-tickets.php on line 170
PHP error occured : msg=syntax error, unexpected '$', expecting ')', no=4, file=C:\inetpub\itopdemo\env-production\itop-tickets\model.itop-tickets.php, line=170
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
<fields><fieldid="cust_ticket_creator_id"xsi:type="AttributeExternalKey"_delta="define"><!--<filter><![CDATA[SELECT Person WHERE org_id = :this->org_id]]></filter>--><!--Huber: Filter = nur Personen die einem Team zugeteilt sind --><filter><![CDATA[SELECT Person AS p JOIN lnkPersonToTeam AS l1 ON l1.person_id=p.id]]></filter><dependencies><attributeid="person_id"/></dependencies><sql>cust_ticket_creator_id</sql><target_class>Person</target_class><is_null_allowed_delta="redefine">true</is_null_allowed><on_target_delete>DEL_AUTO</on_target_delete></field><fieldid="cust_ticket_creator_name"xsi:type="AttributeExternalField"_delta="define"><extkey_attcode>cust_ticket_creator_id</extkey_attcode><target_attcode>name</target_attcode></field></fields>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry if the placeholder does not work (because you are within a PHP method and it does not call the placeholder decoding method, you should directly use
Thanks for the great help. Didn't know that it is this easy - (if you know what to do)
my solution (works as wanted):
<methods><methodid="cus_set_creator_to_current_user"_delta="define"><comment>//sets the custom designed field 'cust_ticket_creator_id' to the logged in user (current_contact_id)</comment><static>false</static><access>public</access><type>Overload-DBObject</type><code><![CDATA[ public function PrefillCreationForm(&$aContextParam) { // Get the current logged-in user as the parameter only provides the login $oUser = UserRights::GetUserObject(); // Prefill field 'cust_ticket_creator_id' with the contact of user $this->SetIfNull('cust_ticket_creator_id', $oUser->Get('contactid')); return true; } ]]></code></method>
🎉
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone,
id designed a custom extension with a new field that represents the creator of the ticket.
What I'd to do further, is to set the default value of the field as the logged in user. Therefore i'm usering the <method> tag. The final goal should be to set the "creator" as ":current_contact_id".</method>
My method is defined as this (it belongs to the class "Ticket"),
Attached find some explaination
kind regards,
G.H.
... i nearly made it working, there was a missunderstanding, i have to declare the function as 'ComputeValues'
Still open: when i define a fixed Value like
$this->SetIfNull('cust_ticket_creator_id', '4');
but it does not work with:
$this->SetIfNull('cust_ticket_creator_id', $this->current_contact_id);
The placeholder to use is $current_contact_id$
Hi Vincent,
now i used: $current_contact_id$
that leads to an error during setup:
Parse error: syntax error, unexpected '$', expecting ')' in C:\inetpub\itopdemo\env-production\itop-tickets\model.itop-tickets.php on line 170
PHP error occured : msg=syntax error, unexpected '$', expecting ')', no=4, file=C:\inetpub\itopdemo\env-production\itop-tickets\model.itop-tickets.php, line=170
... this is how the field is desigend.
Check: https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Aform_prefill#prefill_creation_form
Or, check this documentation: https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Acascade-update : the
GetInitialStateAttributeFlags() and GetAttributeFlag() methods allow you to make some data read-only.
You can always set it using the OnInsert() and OnUpdate() methods of an object.
Sorry if the placeholder does not work (because you are within a PHP method and it does not call the placeholder decoding method, you should directly use
Thanks for the great help. Didn't know that it is this easy - (if you know what to do)
my solution (works as wanted):
For the record: it's recommended to change the method ID to the function name, AFAIK, but great job otherwise :)