CA Service Management

 View Only
Expand all | Collapse all

How to Copy Entries in Custom LRel table

wteixeira

wteixeiraOct 02, 2015 10:39 AM

  • 1.  How to Copy Entries in Custom LRel table

    Posted Oct 01, 2015 03:18 PM

    CA created a custom LREL table for us associated with our Change Orders.  We'd like to copy the records in this table when the change is copied similar to how the usp_lrel_asset_chgnr records are copied when a change is copied.  I haven't been able to figure out how to do this in the tmplcopy_site.spl file.  Anyone have any ideas?  We're using 12.9.

     

    Thanks,

     

    Andrea Holmes



  • 2.  Re: How to Copy Entries in Custom LRel table

    Posted Oct 02, 2015 05:16 AM

    Hi,

    I wrote spel to copy lrel, there 1 thin place but I hope I close it soon.

    Usage:

     

    For example we want to copy Request with attachments.

    1. Open tmplcopy_site.spl;

    2. Find this code:

    cr::copy_cr_site(...) {
      object old, new, alg, gl;
      old=argv[0];
      new=argv[1];
      alg=argv[2];
      gl=argv[3];
    
      //logf(SIGNIFICANT, "cr::copy_cr_site old %s new %s alg %s gl %s",
      // old.ref_num, new.ref_num, alg.persistent_id, gl);
      return;
    }
    
    

    3. Add my function into it:

    cr::copy_cr_site(...) {
      object old, new, alg, gl;
      old=argv[0];
      new=argv[1];
      alg=argv[2];
      gl=argv[3];
      z_lrel_copy(old, new, "lrel_attachments_requests", "cr", "attmnt");
      //logf(SIGNIFICANT, "cr::copy_cr_site old %s new %s alg %s gl %s",
      // old.ref_num, new.ref_num, alg.persistent_id, gl);
      return;
    }
    
    

    4. z_lrel_copy params structure:

    z_lrel_copy(object old_obj,  // Old object (copy from)
                      object new_obj, // New object (copy to)
                      string lrel,           // lrel name
                      string lrel_key,    // lrel key attribute (reference to REL_ATTR of copied object)
                      ...) {                    // attributes to copy, most lrels have only 2 attrs, parent and child, here should be child
    
    

    5. Test with other lrels for your own risk, gl!

     

    Function attached to this post and should be placed to $NX_ROOT/site/mods/majic.

     

    Regards,

    cdtj



  • 3.  Re: How to Copy Entries in Custom LRel table
    Best Answer

    Posted Oct 02, 2015 07:16 AM

    Updated, now it can work with any factory (custom or user defined).

    Tested on attachments to cr and chg both.

    Attachment(s)

    zip
    z_lrel_copy.spl.zip   949 B 1 version
    zip
    z_lrel_copy2.zip   1016 B 1 version


  • 4.  Re: How to Copy Entries in Custom LRel table

    Posted Oct 02, 2015 09:30 AM

    tested on 12.7 and 14.1, could you show an error from stdlog?



  • 5.  Re: How to Copy Entries in Custom LRel table

    Posted Oct 02, 2015 09:50 AM

    hmm, there should be more info, like :

    spelsrvr             4460 ERROR        script.y              3849 D:/PROGRA~1/CA/SERVIC~1/bopcfg/majic/z_lrel_copy.spl at (137) Reference to undeclared symbol old



  • 6.  Re: How to Copy Entries in Custom LRel table

    Posted Oct 02, 2015 10:17 AM

    Now I do have a question.  If there is more than one value in the lrel to copy, how is that delimited in the last parameter?



  • 7.  Re: How to Copy Entries in Custom LRel table

    Posted Oct 02, 2015 10:22 AM

    z_lrel_copy(old, new, "lrel_attachments_requests", "cr", "attmnt", "param2", "param3", "etc");



  • 8.  Re: How to Copy Entries in Custom LRel table

    Posted Oct 02, 2015 10:36 AM

    You are AWESOME!!  This is fantastic!  Thank you so much! 



  • 9.  Re: How to Copy Entries in Custom LRel table

    Posted Sep 23, 2016 05:11 PM

    Hi cdtj,

     

    Thank you for providing this solution.  I'm using it successfully to copy data from two lrel tables on the CR object.  I was wondering if you know what it would take to get this to work with the make_from_template_site function.  It works great on copy_cr_site but not on template.



  • 10.  Re: How to Copy Entries in Custom LRel table

    Posted Sep 24, 2016 06:24 AM

    Hi gbruneau,

    currently i'm out of business and haven't access to any system, but as I remember make_from_template_site method is compiled and cannot be edited, you can try to use text search (like it presented in Total Commander) for bopcfg/majic folder and if method presented as editable code, please provide it here and I hope that I can help you

    Regards,

    cdtj



  • 11.  Re: How to Copy Entries in Custom LRel table

    Posted Sep 25, 2016 12:28 AM

    Sorry to hear you're out of work, hopefully you can pick up another CA Service Desk Manager job soon!

     

    The function make_from_template_site is alongside make_copy in the tmplcopy_site.spl file.  I'll paste the contents of both functions here, they seem to be pretty similar.  Any assistance is appreciated!

     

    // $Header: tmplcopy_site.spl ASPEN.3 2012/03/14 15:40:59 valre03 Exp $

    // Dummy function, just so RCS Id is embedded in compiled spell file...
    string tmplcopy_site_RCSID() { return "@(#)$Id: tmplcopy_site.spl ASPEN.3 2012/03/14 15:40:59 valre03 Exp $"; }

    // Set interpreter option that all variables must be explicitly declared
    #define SYNTAX STRICT

    ////////////////////////////////////////////////////////////////////////
    // Method: cr::make_from_template_site()
    //
    // Description: Exit point for make from template processing
    //
    // Input
    // template argv[0]
    // new cr argv[1]
    // new alg argv[2]
    // gl argv[3]
    //
    // Return
    // none
    ////////////////////////////////////////////////////////////////////////
    cr::make_from_template_site(...) {

    object tmpl, new, alg, gl;
    tmpl=argv[0];
    new=argv[1];
    alg=argv[2];
    gl=argv[3];

    //logf(SIGNIFICANT, "cr::make_from_template_site template %s new %s alg %s gl %s",
    // tmpl.ref_num, new.ref_num, alg.persistent_id, gl);

    return;
    }

    ////////////////////////////////////////////////////////////////////////
    // Method: cr::copy_cr_site()
    //
    // Description: Exit point for copy processing
    //
    // Input
    // old cr argv[0]
    // new cr argv[1]
    // new alg argv[2]
    // gl argv[3]
    //
    // Return
    // none
    ////////////////////////////////////////////////////////////////////////
    cr::copy_cr_site(...) {

    object old, new, alg, gl;
    old=argv[0];
    new=argv[1];
    alg=argv[2];
    gl=argv[3];

    z_lrel_copy(old, new, "zlrel_cr_nr", "cr", "nr");
    z_lrel_copy(old, new, "zlrel_cr_loc", "cr", "loc");

     

    //logf(SIGNIFICANT, "cr::copy_cr_site old %s new %s alg %s gl %s",
    // old.ref_num, new.ref_num, alg.persistent_id, gl);

    return;
    }



  • 12.  Re: How to Copy Entries in Custom LRel table

    Posted Sep 25, 2016 04:36 AM

    I hope so

     

    Looks like the only thing you need is to replace Old object with Template:

     

    cr::make_from_template_site(...) {

    object tmpl, new, alg, gl;
    tmpl=argv[0];
    new=argv[1];
    alg=argv[2];
    gl=argv[3];

    z_lrel_copy(tmpl, new, "zlrel_cr_nr", "cr", "nr");
    z_lrel_copy(tmpl, new, "zlrel_cr_loc", "cr", "loc");

    //logf(SIGNIFICANT, "cr::make_from_template_site template %s new %s alg %s gl %s",
    // tmpl.ref_num, new.ref_num, alg.persistent_id, gl);

    return;
    }

       

    Regards,

    cdtj



  • 13.  Re: How to Copy Entries in Custom LRel table

    Posted Sep 27, 2016 11:28 AM

    Thank you!  You were correct, all I needed to do was change old to tmpl.



  • 14.  Re: How to Copy Entries in Custom LRel table

    Posted Oct 02, 2015 10:39 AM

    Thanks for sharing this cdtj