pls help me with little issue, im sure that you can do it :D
Im trying to set up a field on a firestore document "user_cases_information" with a field "case_number"
- First i declare this global var
private String case_number_consecutive = new String("");
- in
.setOnClickListeneri have this: (to read a old consecutive or case number from other document)
if (service_type.equals("support")){
DocumentReference docRef = firestore_popup.collection("param_data_app").document("support_case_numbers");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
String consecutive = document.get("consecutive").toString();
if (consecutive.equals(null)) {
int random = new Random().nextInt(117) + 4;
case_number_consecutive = "IOC-09"+random;
} else {
case_number_consecutive = consecutive; UpdateCaseNumbersConsecutive("support");
}
} else {
int random = new Random().nextInt(117) + 4;
case_number_consecutive = "IOC-09"+random;
}
}
});
}
Map<String, Object> user_cases_information = new HashMap<>();
user_cases_information.put("case_number", case_number_consecutive);
... (then i use a firestore reference to put the new case number)
It supposed that when i check firestore, precisely the document where i set the "user_cases_information" document, i should see the number or the new case_number, but i always get a null reference, the field consecutive is always = null
Why im getting this null? i used a Toast and put it before this:
Toast.makeText(...."Value: "+case_number_consecutive
Map<String, Object> user_cases_information = new HashMap<>();
user_cases_information.put("case_number", case_number_consecutive);
and it show null so the value or data is losing inside the above functions
how can i fix this??? thank you a lot.