Update a custom field on all Entities with same expiry date

is the screen you want in the image above?

I see it in post #9. stand by

This is why, for some reason its now displaying no data at all thats why it isnt working

Have you logged out and back in? Or maybe restart Samba?

since changing the primary key it now shows the membership number field to have no data when it does

Yea did all thatā€¦

2 Likes

That was probably a bad move.
If inremember right Primary field is entity name in its own column, custom fields are stored in json array.

Changing name of primary field wouldnt make membership number move from custom field to nameā€¦

1 Like

I think if you wanted to change like that would would want to create a name custom field, quick script to copy name to new name custom field, change primary then another action to copy custlm member id to primary field. Would need to check though if there is helper for updating primary/name or would need sql.

what was the reason to change?
I think I looked at similar for selecting entity more easily using numberpad entered rule.
But hastle ended up with script to get entity name from custom field.

yea it does, if you change the primary field name it removes name from the list of fields and replaces it with what ever you set in the primary field

so when changing this here

it changed Name to Membership Number here

and then where membership number was i changed it to Customer Name, the bits of my rule relating to those bits work fine

it does actually show the correct date
image

Here is mine if any use;

function checkId(inputId,currentUser) {
    var customerName            = 'Invalid Swipe';
    var customerCount            = sqlEntityCount('Customers');
    var customerList            = sqlEntityList('Customers');
    for (var c = 0; c<customerCount; c++) {
        var loopCustomer            = customerList[c];
        var loopCustomerFobId        = api.Entity(loopCustomer).Data('Fob Number').Get();
        if (inputId === loopCustomerFobId) {
            var loopCustomerIsStaff            = api.Entity(loopCustomer).Data('Staff Member').Get();
            if (loopCustomerIsStaff == '') {        
                var customerName            = loopCustomer;
                } else {
                var loopCustomerStaffUser    = api.Entity(loopCustomer).Data('Staff User').Get();
                if (loopCustomerStaffUser==currentUser) {
                    var customerName            = 'Own Fob';
                    } else {
                    var customerName            = loopCustomer;
                    }
                }
            break;
            }
        }
    return customerName
}


function customerPriceListTag(inputCustomerName) {
	var customerPriceListTag	= api.Entity(inputCustomerName).Data('Price List Tag').Get();
	if (customerPriceListTag) {
		var response			= customerPriceListTag;
		} else {
		var response			= 'No Price List Defined';
		}
	return response
}

function sqlEntityCount(inputEntityType) {																												//--Entity count by entity type
	qry =  " SELECT COUNT([Name]) as [CT] 							";
	qry += " FROM [Entities] 										";
	qry += " WHERE [EntityTypeId]= 									";
	qry += "					(									";
	qry += "					SELECT [Id]							";
	qry += "					FROM [EntityTypes] 					";
	qry += "					WHERE [Name]='"+inputEntityType+"' 	";
	qry += "					) 									";																					//--QRY Variable + 'roomEntityType' Variable
	var entityCount = sql.Query(qry).First;																												//--SQL Query responce -> entityCount Variable
	return entityCount;																																	//--Return
}

function sqlEntityList(inputEntityType) {																												//--Entity list by entity type
	qry =  " SELECT [Name] 											";
	qry += " FROM [Entities] 										";
	qry += " WHERE [EntityTypeId]= 									";
	qry += "					( 									";
	qry += "					SELECT [Id] 						";
	qry += "					FROM [EntityTypes] 					";
	qry += "					WHERE [Name]='"+inputEntityType+"'	";
	qry += "					) 									";
	qry += " ORDER BY [Name]										";																					//--QRY Variable + 'roomEntityType' Variable
	var entityList = sql.Query(qry).Delimit('~').All;																									//--SQL Query responce -> entitiesList Variable (~ seperated list of entities)
	return entityList;																																	//--Return
}
1 Like

it does display the data
image

so dont know why it suddenly stopped checking the date, nothing changed relating to that part

Thats from my loyalty system so there is extra stuff in there which checks the loyalty field for samba user doesnt match current user so they cant swipe their staff discount card while they are using the till :wink:

HOLD ONā€¦

Where are you calling this?
did you say it was before entity selected for ticket?
Sure the expression is returning in the actual rule not a test action?
Can you test show message in actual rule to ensure the data is available at time of rule fire? Maybe your calling entity data before entity is actually set to ticket?

ill check now, but it worked as is before changing the primary field hang on ill check

Nope it comes up with a show message action in the same rule, that pops up first and displays the correct data, click ok to dismiss the shoe message box and the entity is then added to ticket so the data is there

FIXED IT

I had an action constraint on the block action that referred to {ENTITY DATA:Customer:Membership Number}

But as i changed the primary field to Membership Number this now becomes the Entity Name so changing the action constraint to {ENTITY NAME:Customers} now works as that is actually shown in the entity as the Membership Number Field

2 Likes

BTW I am not sure if this is related as have not read the entire long post. You guys are aware that Tasks can be expired? Tasks would be a great way to build something that needs expiration dates.

image

3 Likes

Just seen this and what I picked up from experience is that when it comes to constraining dates in a simple manner its best to write it down as a number and compare them.

Keep in mind this works only if you donā€™t have to compare different time zones too.

Constrain them in this format yyyyMMdd

Say for user ease of use you put it in dd-MM-yyyy format

  1. Your membership cards expires on 18-08-2020
    Today is 28-07-2020

    TODAY 20200728 is less than EXPIRY DATE 20200818

  2. Works well with lap years too.
    Your membership cards expires on 29-02-2020
    Today is 01-03-2020

    TODAY 20200301 is greater than EXPIRY DATE 20200229

  3. Or after new year
    Your membership cards expires on 31-12-2020
    Today is 01-01-2021

    TODAY 20210101 is greater than EXPIRY DATE 20201231

I never had any issues with this, but like I said if you have to deal with time zones and other offsets it might not work.

2 Likes