I can now get the information from the query into the state but it's not evaluating to false in the createIf. Here's where I'm currently at:
alterState((state) => {
console.log("Altering1...");
const idCards = state.data.form.packets;
state.data.form.packets = [12];
var highestIndex = 0;
[1,2,3,4,5].forEach(function(item, index, array) {
var packetSize = dataValue("form.recapitulatif_.packet"+ item +"-size")(state);
if( typeof packetSize !== "undefined" && packetSize !== "" && typeof packetSize !== 0 && packetSize !== null) {
console.log("Packet Size", packetSize);
state.data.form.packets[highestIndex] = {
savingGoalInsertName: dataValue("form.client_id")(state) + "-2019-" + String(dataValue("form.recapitulatif_.packet"+ item +"-product_name")(state)).replace(/\+/g,"%2B"),
relatedSavingGoal: dataValue("form.client_id")(state) + "-2019-" + String(dataValue("form.recapitulatif_.packet"+ item +"-product_name")(state)),
productId: dataValue("form.recapitulatif_.packet"+ item +"-product_id")(state),
pricebook: dataValue("form.recapitulatif_.packet"+ item +"-pricebook_id")(state),
packetSize: dataValue("form.recapitulatif_.packet"+ item +"-size")(state),
product_type_id: dataValue("form.recapitulatif_.packet"+ item +"-product_type_id")(state)
};
console.log("index", state.data.form.packets[highestIndex] );
highestIndex += 1;
} else {
console.log("Undefined-Packet-Size for item: ", item);
}
});
return state;
})(state),
alterState((state) => {
console.log("Altering2...");
return query("Select Id, Client__c, Program__c , Membership_End_Date__c from Program_Membership__c where Program__c = 'a2H1j0000008Tt6EAE' and Client__c = null")(state);
}),
alterState((state) => {
state.data.form.isProgramMembership = state.references[0].totalSize !== 0;
return state;
});
createIf(dataValue("form.isProgramMembership") , "Program_Membership__c", fields(
relationship("Client__r","Name", dataValue("form.isProgramMembership") ),
field("Program__c", dataValue("form.program_id")),
field("Membership_Start_Date__c",dataValue("form.start_date"))));
combine(function(state) {
if (dataValue("form.meta.username")(state) != "kamara"
& dataValue("form.meta.username")(state) != "eyram"
& dataValue("form.meta.username")(state) != "noella") {
upsert("Client__c","Name", fields(
field("Name", dataValue("form.client_id")(state)),
field("First_Name__c", dataValue("form.demographic_infoss.first_name")(state)),
field("Last_Name__c", dataValue("form.demographic_infoss.last_name")),
field("Sex__c", dataValue("form.demographic_infoss.gender")),
field("Village_Object__c", dataValue("form.village_sf_id"))
))(state),
beta.each(
dataPath("form.packets[*]"),
upsert("Savings_Goal__c","Name", fields(
relationship("Client__r", "Name", dataValue("form.client_id")(state)),
field("Year__c", "2019"),
field("Price_Book__c",dataValue("pricebook")),
field("Name", dataValue("savingGoalInsertName"))
))
)(state),
beta.each(
dataPath("form.packets[*]"),
create("Goal_Items__c", fields(
relationship("Savings_Goal__r", "Name",dataValue("relatedSavingGoal")),
field("Product_Type__c", dataValue("product_type_id")),
field("Product__c", dataValue("productId")),
field("Desired_Units__c", dataValue("packetSize"))
))
)(state);
}
});
If I pass in state after the first alter state function it says "Cannot read property query of undefined", if I pass it into the second it says "Cannot read property zero of undefined".
As a test, I included the value 'form.isProgramMembership' on line 41 and it is evaluating to false when there is zero rows returned.
Thank you for your help.