Update a custom field on all Entities with same expiry date

I think were thinking about it wrong, we need to be checking the current date against the expiry not expiry against current date. Expiry dates will always be set to the future so will always be greater and that membership is valid

What i need to know is when the expiry date has passed, so when the current date is AFTER the expiry date, so

expiry 03 07 2020
Current date 04 07 2020

current date is AFTER expiry therefore membership needs blocking until renewed

so rather than greater or smaller, which i dont think works properly with dates we need BEFORE and AFTER, but in my case i need AFTER

is it possible for your script to be amended to that it is CURRENT date AFTER expiry date?

you new script works, i just needed to swap (expiryDate >= currentDate) around so that current date is greater than expiry date, as membership expires when current date passes (get greater) than membership expiry date

Thanks for you help :slight_smile:

1 Like

ive now slightly changed the setup and use membership number as the primary field and deleted an unused custom field, none of those have anything to do with the expiry field but since i made those changed the script isnt working, on checking rule debugger its not even firing the rule on ticket entity changed

at least i know it works (and all backed up) so just need to figure out why this rule isnt firing now

I don’t know if this will fix the field removed problem. But in your original attempt to constrain the rule (nothing to do with Memo’s script), I noticed you used ADM. ADM is used Add Month(s). However, you used it on both sides, so 2 wrongs will make a right. :stuck_out_tongue_winking_eye:

Here is what ADM looks like:
Nesg6LhixK
Here is what used for a show message action:
Date: {DATE:dd-MM-yyyy}\rEntity: [=FD('{ENTITY DATA:Customers:Membership Expiry}','dd-MM-yyyy')]\rADM: [=FD(ADM('{ENTITY DATA:Customers:Membership Expiry}'),'dd-MM-yyyy')]

Hope this helps in the future.

1 Like

thanks, i have ADM in another part of my setup that Emre helped me with (I didnt know what it meant lol) but was a similar setup so was trying to work it out lol

Here is one of the topics I found that explains it:

1 Like

looks like one of the responses to the setup i was working on lol, forgot all about that description

@Memo

so this is what i dont get, the system works perfect, so when the expired entity it attempted to be loaded to the ticket and is blocked the script works and the rule is fired, once customer pays their membership we press the button on the pos which asks for the customer name and new expiry date, so we type those in and the data updates fine and the block is lifted

perfect!! Almost lol

I now want to change the primary field from customer name to membership number, when i do this the script no longer seems to work and that rule doesnt fire and i cant work out why as nothing to do with the dates or rules for the date checking has been changed so now i have this

Add Member with number 123456

the expiry date is 01012001 so should not load and the warning message should appear
image

any ideas why changing the primary field around has stopped it working?

new entity data
image

I haven’t the foggiest. Does {ENTITY DATA:Customers:Membership Expiry} still return the data you expect?

Post your entity type setup for Customers with custom fields and I’ll play around and see if I can figure something out.

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