ARS-Simple

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

Changes
Config
Config.PL
examples/get_data_by_label.pl
examples/get_list.pl
examples/generate_fid_hash.pl
html/Simple.html
ignore.txt
lib/ARS/Simple.pm
Makefile.PL
MANIFEST			This list of files
README
t/00-load.t
t/01-connect.t
t/config.cache
t/manifest.t
t/pod-coverage.t
t/pod.t
META.yml                                 Module YAML meta-data (added by MakeMaker)
META.json                                Module JSON meta-data (added by MakeMaker)

Makefile.PL  view on Meta::CPAN

        $p = &CCACHE::password;
    }

    print "=== ARS::Simple 'make test' configuration. ===

Test on your own dev system where you know the user you select below
is in the administrator group.

Please enter the following information. This information will be
recorded in ./t/config.cache.  YOU SHOULD REMOVE this file once
you have finished testing as the data is in plain text.

As an alternate, skip testing and install and start trying it out!

If you want to skip the 'make test' step, just hit ENTER
three times. You can configure it later by either re-running
'perl Makefile.PL' or by editting ./t/config.cache

Fair warning: you probably don't want to run 'make test' against a
production Remedy ARS server.

examples/generate_fid_hash.pl  view on Meta::CPAN


print "Enter the name of the Remedy form: ";
my $form = <STDIN>;
chomp $form;

#----------
my $sql = qq{select
f.fieldName,
f.fieldID,
decode(FOption, 1, 'Required ', 2, 'Optional ', 3, 'System RO', '*Unknown*'),
decode(datatype, 0, 'AR_DATA_TYPE_NULL', 1, 'AR_DATA_TYPE_KEYWORD', 2, 'AR_DATA_TYPE_INTEGER', 3, 'AR_DATA_TYPE_REAL', 4, 'AR_DATA_TYPE_CHAR', 5, 'AR_DATA_TYPE_DIARY', 6, 'AR_DATA_TYPE_ENUM', 7, 'AR_DATA_TYPE_TIME', 8, 'AR_DATA_TYPE_BITMASK', 9, 'AR_...
c.maxlength
from arschema a
join field f
on f.schemaid = a.schemaid and datatype < 30 and f.fieldID != 15
left outer join field_char c
on c.schemaid = f.schemaid and c.fieldid = f.fieldID
where a.name = '$form'
order by 1};


my $m = $ars->get_SQL({ sql => $sql });

### Sample data for 'User' form
# my $m = {
# numMatches => 30,
# rows => [
# [ 'CreateDate'               , 3,            'System RO', 'AR_DATA_TYPE_TIME', undef ],
# [ 'LastModifiedBy'           , 5,            'System RO', 'AR_DATA_TYPE_CHAR', 254 ],
# [ 'ModifiedDate'             , 6,            'System RO', 'AR_DATA_TYPE_TIME', undef ],
# [ 'RequestID'                , 1,            'System RO', 'AR_DATA_TYPE_CHAR', 15 ],
# [ 'Creator'                  , 2,            'Required', 'AR_DATA_TYPE_CHAR', 254 ],
# [ 'FullName'                 , 8,            'Required', 'AR_DATA_TYPE_CHAR', 254 ],
# [ 'FullTextLicenseType'      , 110,          'Required', 'AR_DATA_TYPE_ENUM', undef ],

examples/generate_fid_hash.pl  view on Meta::CPAN

# [ 'ChangeLicenseUsed'        , 220000003,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'HelpDeskLicenseUsed'      , 220000004,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'NumberofLicenseAvailable' , 220000000,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'SLALicenseUsed'           , 220000001,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# ],
# };


unless ($m && $m->{numMatches})
{
    print "No data returned, quitting\n";
    exit;
}

# Check size and replace spaces with '_', you could also remove them!
my $max_len = 0;
foreach my $row (@{ $m->{rows} })
{
    $row->[0] =~ s/\s+/_/gms;
    if (length($row->[0]) > $max_len)
    {

examples/generate_fid_hash.pl  view on Meta::CPAN


# Construct the hash
my $fid_hash = "# Label/FID hash for form '$form'\n\%fid = (\n";
foreach my $row (@{ $m->{rows} })
{
    $fid_hash .= sprintf("    '%s'%s=> %10d,\t\t# %s type=%s %d\n", $row->[0], ' ' x ($max_len + 1 - length($row->[0])), $row->[1], $row->[2], $row->[3], $row->[4]);
}
$fid_hash .= "    );\n";

$CLIP->Set($fid_hash);
print "$fid_hash\nFormatted data copied to clipboard\n";

examples/get_data_by_label.pl  view on Meta::CPAN

        'FromConfig'               => 250000003,    # Optional  type=AR_DATA_TYPE_CHAR 3
        'GroupList'                => 104,          # Optional  type=AR_DATA_TYPE_CHAR 255
        'UniqueIdentifier'         => 179,          # Optional  type=AR_DATA_TYPE_CHAR 38
        'AssetLicenseUsed'         => 220000002,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'ChangeLicenseUsed'        => 220000003,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'HelpDeskLicenseUsed'      => 220000004,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'NumberofLicenseAvailable' => 220000000,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'SLALicenseUsed'           => 220000001,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        );

my $data = $ars->get_data_by_label({
        form        => 'User',
        query       => '1=1',
        lfid        => \%fid,
        max_returns => 50,
        });

print Dumper($data), "\n";

html/Simple.html  view on Meta::CPAN


<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#VERSION">VERSION</a></li>
  <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="#METHODS">METHODS</a>
    <ul>
      <li><a href="#new">new</a></li>
      <li><a href="#get_list">get_list</a></li>
      <li><a href="#get_SQL">get_SQL</a></li>
      <li><a href="#get_data_by_label">get_data_by_label</a></li>
      <li><a href="#get_fields">get_fields</a></li>
      <li><a href="#set_max_entries">set_max_entries</a></li>
    </ul>
  </li>
  <li><a href="#PRIVATE-METHODS">PRIVATE METHODS</a>
    <ul>
      <li><a href="#init">_init</a></li>
      <li><a href="#load_qualifier">_load_qualifier</a></li>
      <li><a href="#DESTROY">DESTROY</a></li>
      <li><a href="#check_initialised">_check_initialised</a></li>

html/Simple.html  view on Meta::CPAN

     <span class="operator">}</span><span class="operator">);</span>
 
 <span class="comment"># Get the Entry-ID/Request-ID for all User's with Login starting with 'g'</span>
 <span class="comment"># Here $eid is any array reference of entry-id/request-id values</span>
 <span class="keyword">my</span> <span class="variable">$eid</span> <span class="operator">=</span> <span class="variable">$ar</span><span class="operator">-&gt;</span><span class="variable">get_list</span><span class="operator">(</span><span class="...
     <span class="string">form</span>  <span class="operator">=&gt;</span> <span class="string">'User'</span><span class="operator">,</span>
     <span class="string">query</span> <span class="operator">=&gt;</span> <span class="string">qq{'Login' LIKE "g%"}</span><span class="operator">,</span>
     <span class="operator">}</span><span class="operator">);</span>
 <span class="keyword">print</span> <span class="variable">Data::Dumper</span><span class="operator">-&gt;</span><span class="variable">Dump</span><span class="operator">(</span><span class="operator">[</span><span class="variable">$eid</span><span c...
 
 <span class="comment"># Get data from a form, based on a query (as you would use in the User Tool)</span>
 <span class="keyword">my</span> <span class="variable">%lfid</span> <span class="operator">=</span> <span class="operator">();</span>
 <span class="keyword">my</span> <span class="variable">$form</span>  <span class="operator">=</span> <span class="string">'User'</span><span class="operator">;</span>
 <span class="keyword">my</span> <span class="variable">$query</span> <span class="operator">=</span> <span class="string">qq('FID' = "value")</span><span class="operator">;</span>
 <span class="keyword">my</span> <span class="variable">$data</span> <span class="operator">=</span> <span class="variable">$ar</span><span class="operator">-&gt;</span><span class="variable">get_data_by_label</span><span class="operator">(</span><sp...
 <span class="string">form</span>  <span class="operator">=&gt;</span> <span class="variable">$form</span><span class="operator">,</span>
 <span class="string">query</span> <span class="operator">=&gt;</span> <span class="variable">$query</span><span class="operator">,</span>
 <span class="string">lfid</span>  <span class="operator">=&gt;</span> <span class="operator">{</span> <span class="variable">label1</span><span class="operator">,</span> <span class="variable">fid1</span><span class="operator">,</span> <span class="...
 <span class="operator">}</span><span class="operator">);</span>
</code></pre>

<h1 id="METHODS">METHODS</h1>

<h2 id="new">new</h2>

html/Simple.html  view on Meta::CPAN

<p>the a query could be something like</p>

<pre><code> <span class="keyword">my</span> <span class="variable">$query</span> <span class="operator">=</span> <span class="string">qq{ '</span><span class="variable">$user</span><span class="string">{UserID}' LIKE "g%" }</span><span class="operato...
 <span class="keyword">my</span> <span class="variable">$eids</span> <span class="operator">=</span> <span class="variable">$ars</span><span class="operator">-&gt;</span><span class="variable">get_list</span><span class="operator">(</span><span class...
</code></pre>

<h2 id="get_SQL">get_SQL</h2>

<p>Run direct SQL on your server, there is only one required argument, the sql, you may optionally set the max_returns value.</p>

<p>The names of the fields can be found from the Admin Tool, under the database tab for a form. This will be the name of the field used in the database view of the Remedy form. <b>Note</b> you do need to replace spaces with and underscore &#39;_&#39;...

<p>Example method call:</p>

<pre><code> <span class="keyword">my</span> <span class="variable">$data</span> <span class="operator">=</span> <span class="variable">$ars</span><span class="operator">-&gt;</span><span class="variable">get_SQL</span><span class="operator">(</span><...
     <span class="string">sql</span> <span class="operator">=&gt;</span> <span class="string">q{select Login_name, Full_Name from User_X where Login_name like 'g%' order by Login_name}</span><span class="operator">,</span>
     <span class="string">max_returns</span> <span class="operator">=&gt;</span> <span class="number">0</span><span class="operator">,</span>
     <span class="operator">}</span><span class="operator">);</span>
</code></pre>

<p>The return is a hash reference with two keys, numMatches and rows, example:</p>

<pre><code> <span class="variable">$data</span> <span class="operator">=</span> <span class="operator">{</span>
     <span class="variable">numMatches</span> <span class="operator">=</span> <span class="operator">&gt;</span> <span class="number">2</span><span class="operator">,</span>
     <span class="string">rows</span> <span class="operator">=&gt;</span> <span class="operator">[</span>
        <span class="string">'greg'</span><span class="operator">,</span> <span class="string">'Greg George'</span><span class="operator">,</span>
        <span class="string">'geoff'</span><span class="operator">,</span> <span class="string">'Geoffery Wallace'</span><span class="operator">,</span>
     <span class="operator">]</span>
 <span class="operator">}</span><span class="operator">;</span>
</code></pre>

<h2 id="get_data_by_label">get_data_by_label</h2>

<p>Query a form and get the data back as a hash reference where the keys are the Entry-Id&#39;s for the records matched by the query and the value is a hash reference to the fields you requested where the keys are the field names you used and the val...

<pre><code> <span class="keyword">my</span> <span class="variable">$form</span>  <span class="operator">=</span> <span class="string">'form'</span><span class="operator">;</span>
 <span class="keyword">my</span> <span class="variable">$query</span> <span class="operator">=</span> <span class="string">qq('FID' = "value")</span><span class="operator">;</span>
 <span class="keyword">my</span> <span class="variable">$data</span> <span class="operator">=</span> <span class="variable">$ar</span><span class="operator">-&gt;</span><span class="variable">get_data_by_label</span><span class="operator">(</span><sp...
     <span class="string">form</span>  <span class="operator">=&gt;</span> <span class="variable">$form</span><span class="operator">,</span>
     <span class="string">query</span> <span class="operator">=&gt;</span> <span class="variable">$query</span><span class="operator">,</span>
     <span class="string">lfid</span>  <span class="operator">=&gt;</span> <span class="operator">{</span> <span class="variable">label1</span><span class="operator">,</span> <span class="variable">fid1</span><span class="operator">,</span> <span cla...
     <span class="operator">}</span><span class="operator">);</span>
 
 <span class="variable">$data</span> <span class="operator">=</span> <span class="operator">{</span>
     <span class="variable">eID1</span><span class="operator">,</span> <span class="operator">{</span><span class="string">Label1</span> <span class="operator">=&gt;</span> <span class="variable">value1</span><span class="operator">,</span> <span cla...
     <span class="variable">eID2</span><span class="operator">,</span> <span class="operator">{</span><span class="string">Label1</span> <span class="operator">=&gt;</span> <span class="variable">value1</span><span class="operator">,</span> <span cla...
     <span class="operator">...</span>
     <span class="operator">}</span><span class="operator">;</span>
</code></pre>

<h2 id="get_fields">get_fields</h2>

<p>get_fields has a required argument, the form you require the field details for. The returned hash reference is the result of a call to ars_GetFieldTable, the keys are the field names and the values are the field ids (fid).</p>

html/Simple.html  view on Meta::CPAN

<h1 id="TODO">TODO</h1>

<p>Add in the tools below.</p>

<p>Add in further methods to make life easier and your code more readable</p>

<h1 id="TOOLS">TOOLS</h1>

<p><b>NOT DONE YET</b></p>

<p>The lfid array used by the get_data_by_label() method required that a hash is defined which describes the field lables (names) you want to use mapped to the field ID (FID). The encluded script will construct such a hash for all relavent fields. Yo...

<p>There is a win32 version of this which copies the data to your clipboard, to make your life easier.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>Greg George, <code>&lt;gng at cpan.org&gt;</code></p>

<h1 id="BUGS">BUGS</h1>

<p>Please report any bugs or feature requests to <code>bug-ars-simple at rt.cpan.org</code>, or through the web interface at <a href="http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ARS-Simple">http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ARS-Simple...

<h1 id="SUPPORT">SUPPORT</h1>

lib/ARS/Simple.pm  view on Meta::CPAN


    # Create a qualifier struct
    my $qual = $self->_load_qualifier($args);
    return unless $qual;

    # Set the limit
    $self->set_max_entries($args->{max_returns});

    # Get the entryId
    my @entries = ars_GetListEntry($self->{ctl}, $args->{form}, $qual, 0, 0,
        [{columnWidth => 1, separator => ' ', fieldId => 1 }]  # Minimise the amount of data returned
        );

    # Reset the limit
    $self->_reset_max_entries();


    my @entryIds;
    # Speed hack for large retuns
    $#entryIds = $#entries;
    @entryIds = ();

lib/ARS/Simple.pm  view on Meta::CPAN


    my $qual = ars_LoadQualifier($self->{ctl}, $args->{form}, $args->{query});
    unless ($qual)
    {
        $self->_carp("_load_qualifier() Error processing query:\n$ars_errstr\n");
    }

    return $qual;
}

sub get_data_by_label
{
    my ($self, $args) = @_;

    my $form    = $args->{form};
    my $query   = $args->{query};
    my $lfid_hr = $args->{lfid};
    my @fid     = values %$lfid_hr;

    # Check ARSystem initailised
    return unless $self->_check_initialised();

    # Check required args
    unless ($args->{form} && $args->{query})
    {
        $self->_carp("get_data_by_label() requires 'form' and 'query' arguments\n");
        return;
    }

    #-- Create a qualifier struct
    my $qual = $self->_load_qualifier($args);
    return unless $qual;

    # Set the limit
    $self->set_max_entries($args->{max_returns});

    # Get the data from the form defined by qualifier qual
    my %entryList;
    if ($ARS::VERSION >= 1.8)
    {
        %entryList = ars_GetListEntryWithFields($self->{ctl}, $form, $qual, 0, 0, \@fid);
    }
    else
    {
        %entryList = ars_GetListEntryWithFields($self->{ctl}, $form, $qual, 0, \@fid);
    }

    # Reset the limit
    $self->_reset_max_entries();

    unless (%entryList)
    {
        no warnings qw(uninitialized);
        if ($ars_errstr)
        {
            $self->_carp("get_data_by_label() failed.\nError=$ars_errstr\nForm=$form\nQuery=$query\n");
        }
        else
        {
            if ($self->{log})
            {
                $self->{log}->msg(3, "get_data_by_label() no records found.\n");
            }
        }
        return;
    }

    # Map the FID's to Labels in the hashs
    my %fid2label = reverse %$lfid_hr;
    foreach my $eID (keys %entryList)
    {
        foreach my $fid (keys %{$entryList{$eID}})

lib/ARS/Simple.pm  view on Meta::CPAN

        }
    }


    my $rv = ars_SetEntry($self->{ctl}, $form, $eID, 0, %lvp);

    # Check for errors
    unless (defined $rv && $rv == 1)
    {
        # Update failed
        my $msg = "update_record(eid=$eID, form=$form, ...) failed:\nars_errstr=$ars_errstr\nlvp data was:\n";
        foreach my $label (sort keys %{$args->{lvp}})
        {
            $msg .= sprintf("%30s (%10d) ---> %s\n", $label, $args->{lfid}{$label}, defined($lvp{$args->{lfid}{$label}}) ? $lvp{$args->{lfid}{$label}} : '<undefined>');
        }
        carp($msg);
    }
    return $rv;
}

sub get_ctl

lib/ARS/Simple.pm  view on Meta::CPAN

 use ARS::Simple;

 my $ar = ARS::Simple->new({
     server   => 'my_remedy_server',
     user     => 'admin',
     password => 'admin',
     });

 ### Get the Entry-ID/Request-ID for all User's with Login starting with 'g'
 # Here $eid is any array reference of entry-id/request-id values
 my $data = $ar->get_list({
     form  => 'User',
     query => qq{'Login' LIKE "g%"},
     });
 print Data::Dumper->Dump([$data], ['data']), "\n";
 # Resulting data dump:
 # $data = {
 #   'eids' => [
 #     '000000000004467',
 #     '000000000004469',
 #     '000000000004470',
 #   ],
 #   'numMatches' => 3
 #};

 ### Get data from a form, based on a query (as you would use in the User Tool)
 my $form  = 'User';
 my $entryListLabel = $ar->get_data_by_label({
     form  => $form,
     query => qq{'Login Name' LIKE "ge%"},  # Login Name = FID 101
     lfid  => { 'LoginName', 101, 'FullName', 8, 'LicenseType', 109, },
     });
 print Data::Dumper->Dump([$entryListLabel], ['entryListLabel']), "\n";
 # Resulting data dump:
 # $entryListLabel = {
 #  '000000000014467' => {
 #    'FullName' => 'Geoff Batty',
 #    'LicenseType' => 0,
 #    'LoginName' => 'gbatty'
 #  },
 #  '000000000014469' => {
 #    'FullName' => 'Greg George',
 #    'LicenseType' => 2,
 #    'LoginName' => 'gregg'

lib/ARS/Simple.pm  view on Meta::CPAN

default field name as they may change.  I prefer to define a hash of the
forms lables and FID's so that can be used to better document your code, eg

 my %user = ( UserID => 101, UserName => 102 );

the a query could be something like

 my $query = qq{ '$user{UserID}' LIKE "g%" };
 my $eids = $ars->get_list({ form => 'User', query => $query });

=head2 get_data_by_label

Query a form and get the data back as a hash reference where the
keys are the Entry-Id's for the records matched by the query and
the value is a hash reference to the fields you requested where
the keys are the field names you used and the value are the values.

 my $form  = 'form';
 my $query = qq('FID' = "value");
 my $data = $ar->get_data_by_label({
     form  => $form,
     query => $query,
     lfid  => { label1, fid1, label2, fid2, ...},
     });

 $data = {
     eID1, {Label1 => value1, Label2 => value2, ...},
     eID2, {Label1 => value1, Label2 => value2, ...},
     ...
     };

=head2 update_record

Update a record on a form based on the Entry-Id (eid).  The
data to update is defined in the lvp (label value pair) hash reference.
The other required argument is the lfid (label FID) hash reference which
is used to map the labels to field Ids (FID).

The method returns true on success and carps on error.

update_record({
    eid  => $eID,           # The Entry-Id/Request-Id to update
    form => $form,          # The form to update
    lvp  => \%lvp,          # The data to be updated as a label => value hash ref
    lfid => \%labelFIDhash  # The label FID hash reference
    });

=head2 get_SQL

Run direct SQL on your server, there is only one required argument,
the sql, you may optionally set the max_returns value.

The names of the fields can be found from the Admin Tool, under
the database tab for a form.  This will be the name of the field
used in the database view of the Remedy form. B<Note> you do need
to replace spaces with and underscore '_' character.

Example method call:

 my $data = $ars->get_SQL({
     sql => q{select Login_name, Full_Name from User_X where Login_name like 'g%' order by Login_name},
     max_returns => 0,
     });

The return is a hash reference with two keys, numMatches and rows, example:

 $data = {
     numMatches = > 2,
     rows => [
        'greg', 'Greg George',
        'geoff', 'Geoffery Wallace',
     ]
 };

=head2 get_ctl

Returns the ARSystem control structure, so you can use it in other

lib/ARS/Simple.pm  view on Meta::CPAN

=head1 TODO

Add in the tools below.

Add in further methods to make life easier and your code more readable

=head1 TOOLS

B<NOT DONE YET>

The lfid array used by the get_data_by_label() method
required that a hash is defined which describes the
field lables (names) you want to use mapped to the
field ID (FID).  The encluded script will construct
such a hash for all relavent fields.  You might like
to edit this down to only those fields you really need
thereby reducing the amount of data returned.

There is a win32 version of this which copies the data
to your clipboard, to make your life easier.

=head1 AUTHOR

Greg George, C<< <gng at cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-ars-simple at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ARS-Simple>.  I will be notified, and then you'll



( run in 0.427 second using v1.01-cache-2.11-cpan-2b0bae70ee8 )