The scrip do all sorts of things, so I just put the relevant bits below
Condition: On Create
Action: User Defined
Custom action preparation code: return 1;
Custom action cleanup code:
#Assumption ticket is created via mail/web by a customer contact.
#So creator == requestor
my $req =$self->TicketObj->CreatorObj ;
my $org = $req->ContactMembership ; #ContactMembership explained below
if ($org) {
#We found this requestor belong to a Customer group
my $g_obj = RT::Group->new(RT::SystemUser);
$g_obj->LoadUserDefinedGroup($org);
my $service_id = $g_obj->FirstCustomFieldValue('Service_Order');
my $service_valid_from =
$g_obj->FirstCustomFieldValue('Service_Order_Start');
my $service_expire = $g_obj->FirstCustomFieldValue('Service_Order_Expire');
$self->{custfield}=RT::CustomField->new(RT::SystemUser);
$self->{custfield}->LoadByName(Name=> 'Customer_name');
$self->{TicketObj}->AddCustomFieldValue(Field=>$self->{custfield},Value=>
$org);
$self->{custfield2}=RT::CustomField->new(RT::SystemUser);
$self->{custfield2}->LoadByName(Name=> 'Service_Order_Number');
$self->{TicketObj}->AddCustomFieldValue(Field=>$self->{custfield2},Value=>
$service_id);
$self->{custfield3}=RT::CustomField->new(RT::SystemUser);
$self->{custfield3}->LoadByName(Name=> 'Service_Order_Number_Expire_Date');
$self->{TicketObj}->AddCustomFieldValue(Field=>$self->{custfield3},Value=>
$service_expire );
return 1;
} else {
return undef;
}
ContactMembership is a function I written and put it in User_Vendor.pm.
There are few ways to extract groups a user belong to , but I needed one
specific to customers.
sub ContactMembership {
# Identify a group a user belong to
# Used in scrip action to identify cust contact
# Expects a user id and return group name
# If user belong to more than one it returns undef
# This should not happen with customer contacts
my $self = shift;
my $MemberId = $self->Id ;
my $group_list = '';
my $Groups = RT::Groups->new($RT::SystemUser);
$Groups->Limit( FIELD => 'Description',OPERATOR => 'LIKE', VALUE =>
'Customer-');
$Groups->Limit( FIELD => 'Domain',OPERATOR => '=', VALUE =>
'SystemInternal');
$Groups->Limit( FIELD => 'Domain',OPERATOR => '=', VALUE =>
'UserDefined');
my $alias = $Groups->Join(
TYPE => 'left',
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'GroupMembers',
FIELD2 => 'GroupId'
);
$Groups->Limit(
ALIAS => $alias,
FIELD => 'MemberId',
OPERATOR => '=',
VALUE => $MemberId,
);
return undef unless $Groups->Count == 1 ;
return $Groups->First->Name ;
}
As I mentioned I removed bits from the scrip and the function, so please check
the code for any errors.
Note my customer groups have their description starting with Customer-
Regards;
Roy
From: Walid Haider [mailto:[email protected]]
Sent: 24 March 2011 14:53
To: Raed El-Hames; [email protected]
Subject: RE: Support Contract Client Check
Hi Roy,
Thanks for your response, any chance you can send me an example of the global
scrip you are using?
Regards,
Walid
From: Raed El-Hames [mailto:[email protected]]
Sent: quinta-feira, 24 de Março de 2011 12:10
To: Walid Haider; [email protected]
Subject: RE: Support Contract Client Check
Walid:
I've done something similar but my approach was slightly different.
My customers in most cases have more than one contact, so for every customer I
created a group, and added their contacts as members of their group, the group
name is the customer name, and I added a couple of group custom fields,
contract_name and contract_expire_date.
When any of the contacts create a ticket, there is a global scrip that identify
the requestor and if it belongs to a customer group it populates a ticket
custom field customer_name with the name of the group the requestor belongs to,
it also populates ticket custom fields relating to contract name and expire
grabbed from the group custom fields.
To keep my RT in sync with the CRM system (to update the customer and contract
information), I run daily script that export this info from CRM and update the
group custom fields within my RT.
Hope this helps.
Regards;
Roy
From: [email protected]
[mailto:[email protected]] On Behalf Of Walid Haider
Sent: 24 March 2011 11:54
To: [email protected]
Subject: [rt-users] Support Contract Client Check
Hi,
I am running RT 3.8.4 and have created a custom field, with a list of all our
clients, so that the client name is selected from the list when creating or
updating a ticket.
I am now looking to implement a way of checking if the client's support
contract has not expired (and perhaps even, displaying a message informing the
RT user that the client's contract has expired and also highlighting the custom
field in red - under ticket metadata - when viewing existing tickets referring
to clients that do not have valid support contract).
This support contract information is available in an excel spreadsheet that I
could either:
· link to RT in some way (of course, the danger here is that in order
for this to work, the name of client must be exactly the same as in RT) or;
· update the support contract information in RT form time to time
(probably safer this way)
In future, I would also like to allow our clients to be able to view and update
their own tickets, and would also like to deny access (automatically, based on
the check above) if the support contract has expired - possibly displaying a
message informing the user that why the access was denied.
I would really appreciate in if someone could point me in the right direction.
Thanks and regards,
Walid