Custom table - Table Level Script

SUGGESTED

Help! Please!  I think I am running into an issue with a table level script where perhaps I cannot see the forest for the trees. :-(

I have a custom entity and if I update a field on that entity, I want to update another field on the same entity and other fields on other custom entities using the field I just updated.

I am able to update the other fields on other custom entities just fine...but I cannot get another field on the same entity to update using the field I just updated.

The custom entities are Property, Unit, Tenant, Lease.  A Tenant's LeaseNum is made up of a PropertyNum and a TenantNum.  Therefore, if I update the TenantNum on the Tenant, I want the LeaseNum on that record to update as well.  I cannot get this to  work and I am not sure what I am doing wrong.  Originally I was using Values() to update the LeaseNum field.  It would appear correctly on the screen after save.  However, as soon as I refreshed the screen, the TenantNum portion would come back undefined.  Therefore, I updated it to what I have below.  Everything in this table level script works as desired...except for the update to the LeaseNum on the Tenant Record.  I have highlighted the portion that is NOT working.

The LeaseNum updates correctly on the Unit and Lease record using the same variables.  However, there is NO CHANGE to the LeaseNum on the Tenant record.

Any assistance would be greatly appreciated!!!

function UpdateRecord()
{

var tenant = CRM.FindRecord('Tenant',WhereClause);
var propID = tenant.tena_propertyid;
var tenantnumD = tenant.tena_number;
var tenantnumV = Values("tena_number");

var prop = CRM.FindRecord('Property', 'prop_propertyid='+propID);
var propnumD = prop.prop_number;

var unit = CRM.FindRecord('Unit', 'unit_propertyid='+propID);
var lease = CRM.FindRecord('Lease', 'leas_propertyid='+propID);

//Change to tenant number============================================
if (tenantnumD!=tenantnumV) {

//Update Tenant Record--------------------------------------------------------------------------------
//LeaseNum = PropNum-TenantNum
while (!tenant.EOF)
{
tenant.tena_leasenum = propnumD+'-'+tenantnumV;
tenant.NextRecord();
}
tenant.SaveChangesNoTLS();


//Update Lease Record---------------------------------------------------------------------------------
while (!lease.EOF)
{
lease.leas_tenantnum = tenantnumV;
lease.leas_number = propnumD+'-'+tenantnumV;
lease.NextRecord();
}
lease.SaveChangesNoTLS();

//Update Unit record-------------------------------------------------------------------------------------
while (!unit.EOF)
{
unit.unit_tenantnum = tenantnumV;
unit.unit_number = 1;
unit.unit_leasenum = propnumD+'-'+tenantnumV;
unit.NextRecord();
}
unit.SaveChangesNoTLS();

}
}

Parents Reply
  • 0 in reply to Michele Gaw

    This does work..the value in the field is correctly set when returning to the screen after clicking save.

    //Update Tenant Record--------------------------------------------------------------------------------
    //LeaseNum = PropNum-TenantNum
    Value("tena_leasenum") = propnumD+'-'+tenantnumV;

    I just don't understand why the value changes if I then refresh the screen. Is that normal?

Children
  • 0 in reply to Michele Gaw
    SUGGESTED

    You would need to look at how the value was being 'set'.  Do you have a default value in the field or a script that addresses the field when you enter the screen?

  • 0 in reply to Sage CRM

    Ok...Thanks!  I will explore that further. 

    I guess I thought when I hit "refresh" it would draw the data from the database.

    However, I am guessing that based on the "mode" I am in, it is trying to draw from scripts for the screen rather than directly from the database.  For the scripts, it cannot "set" that piece and is being returned as undefined.

    Therefore, I will see what scripts might be causing the undefined piece.

    Thanks!

    PS...it would be rare that a user would hit "refresh" at that point...but I did and it was confusing.