+=item clone NEW_SVCNUM
+
+Clones this rule into an identical rule for the specified new service.
+
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
+#should return the newly inserted rule instead? used in misc/clone-cgp_rule.html
+
+#i should probably be transactionalized so i'm all-or-nothing
+sub clone {
+ my( $self, $svcnum ) = @_;
+
+ my $new = $self->new( { $self->hash } );
+ $new->rulenum('');
+ $new->svcnum( $svcnum );
+ my $error = $new->insert;
+ return $error if $error;
+
+ my @dup = $self->cgp_rule_condition;
+ push @dup, $self->cgp_rule_action;
+
+ foreach my $dup (@dup) {
+ my $new_dup = $dup->new( { $dup->hash } );
+ my $pk = $new_dup->primary_key;
+ $new_dup->$pk('');
+ $new_dup->rulenum( $new->rulenum );
+
+ $error = $new_dup->insert;
+ return $error if $error;
+
+ }
+
+ $error = $new->svc_export;
+ return $error if $error;
+
+ '';
+
+}
+
+=item cust_svc
+
+=cut
+
+sub cust_svc {
+ my $self = shift;
+ qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
+}
+
+=item cgp_rule_condition
+
+Returns the conditions associated with this rule, as FS::cgp_rule_condition
+objects.
+
+=cut
+
+sub cgp_rule_condition {
+ my $self = shift;
+ qsearch('cgp_rule_condition', { 'rulenum' => $self->rulenum } );
+}
+
+=item cgp_rule_action
+
+Returns the actions associated with this rule, as FS::cgp_rule_action
+objects.
+
+=cut
+
+sub cgp_rule_action {
+ my $self = shift;
+ qsearch('cgp_rule_action', { 'rulenum' => $self->rulenum } );
+}
+
+=item arrayref
+
+Returns an arraref representing this rule, suitable for Communigate Pro API
+commands:
+
+The first element specifies the rule priority.
+
+The second element specifies the rule name.
+
+The third element specifies the rule conditions.
+
+The fourth element specifies the rule actions.
+
+The fifth element specifies the rule comment.
+
+=cut
+
+sub arrayref {
+ my $self = shift;
+ [ $self->priority,
+ $self->name,
+ [ map $_->arrayref, $self->cgp_rule_condition ],
+ [ map $_->arrayref, $self->cgp_rule_action ],
+ $self->comment,
+ ],
+}
+