Skip to main content

Notifications

Power Up Program - Build A Canvas App
Unanswered

why i am not getting a refreshed item from sharePoint unless i do Refresh() operation

Like (1) ShareShare
ReportReport
Posted on 6 Oct 2024 14:57:22 by 1,378
I have a Work Order SharePoint list with a field named Technician. and 3 screen:-
 
1) Work Order screen. With a button to "Assign" the work order to the login user incase the work order is not assigned to the login user.
2) Work Order Screen. With upload photo, and check if the user who is uploading the picture is the work order technician.
3) Work Order Spare Part Screen. With upload photo, and check if the user who is uploading the picture is the work order technician.
 
Here is the code to "Assign" the work order, which mainly calls a workflow and it update the work order technician, then i get a fresh version of the work order:-
Set(
    varTempWorkOrder,
    LookUp(
        'Work Orders',
        ID = ThisItem.ID
    )
);
    If(
        ThisItem.'Work Order Status'.Value = "Assigned" || ThisItem.'Work Order Status'.Value = "New",
        Set(
            Response,
            'GrantaccesstoWorkOrder(Elevated)'.Run(
                ThisItem.ID,
                ""
            ).response
        );
        If(
            Response <> "Done",
            Notify(
                "Error when Assign",
                NotificationType.Error
            ),
            //Refresh('Work Orders');
            Set(
                varWorkOrder,
                LookUp(
                    'Work Orders',
                    ID = ThisItem.ID
                )
            );
            Navigate('WorkOrder CRUD');
            Notify(
                "Done",
                NotificationType.Success
            )
        )
    );
    If(
        ThisItem.'Work Order Status'.Value = "Done",
        //Refresh('Work Orders');
        Set(
            varWorkOrder,
            LookUp(
                'Work Orders',
                ID = ThisItem.ID
            )
        );
        Navigate('WorkOrder CRUD')
    );
 
 
Here is the code for the Work Order screen OnVisible():-
Set(
    varWorkOrderDetails,
    LookUp(
        'Work Orders Info Details',
        ID = LookUp(
            'Work Orders Work Order Info Details',
            'Work Order ID' = varWorkOrder.ID
        ).'Work Order Info Detail ID'
    )
);
Clear(colDelegableDocumentsResults);
ClearCollect(
    colAttachmentDocumentsRelatedID,
    Filter(
        AttachmentDocumentsRelatedID,
        'Work Order ID' = varWorkOrder.ID
    )
);
ForAll(
    colAttachmentDocumentsRelatedID As ForAllRecord,
    Collect(
        colDelegableDocumentsResults,
        Filter(
            AttachmentDocuments,
            ActiveStatus.Value = "Active" And ID = ForAllRecord.RelatedDocumentID And ('Picture Type'.Value = "After" Or 'Picture Type'.Value = "Before")
        )
    )
);
Refresh(AttachmentDocumentsRelatedID);
Refresh(AttachmentDocuments);
 
Here is the check when uploding a new photo inside the work order:-
If(
    Lower(varWorkOrder.'Technician Name'.Email) = Lower(User().Email),
//code goes here
    Select(ReusableFormulas),
    Notify(
        "Can not upload a photo for work order not assigned to you",
        NotificationType.Error,
        10000
    )
);
 
 
Here is the code for the Work Order Spare Part screen OnVisible():-
Clear(colSpareParts);
Set(varWorkOrderMediumID,Blank());
Refresh(AttachmentDocumentsRelatedID);
Refresh(AttachmentDocuments);
Refresh('Work Orders Spare Parts');
Refresh('Work Orders Spare Part Details');
Set(
    varWorkOrderDetails,
    LookUp(
        'Work Orders Info Details',
        ID = LookUp(
            'Work Orders Work Order Info Details',
            'Work Order ID' = varWorkOrder.ID
        ).'Work Order Info Detail ID'
    )
);
Set(varWorkOrderATID,LookUp(Assets,ID=varWorkOrder.'Asset ID').'Asset Type ID');
ClearCollect(colSpareParts,ShowColumns(Filter('Spare Parts Asset Types','Asset Type ID'=varWorkOrderATID && ActiveStatus.Value="Active"),'Spare Part ID'));
ClearCollect(colIssueTypes,ShowColumns(Filter(IssueTypesAssetTypes,'Asset Type ID'=varWorkOrderATID && ActiveStatus.Value="Active"),'Issue Type ID'));
 
Here is the check when uploading new photos inside the work order spare part:-
If(
    Lower(varWorkOrder.'Technician Name'.Email) = Lower(User().Email),
//code goes here
    Select(ReusableFormulas),
    Notify(
        "Can not upload a photo for work order not assigned to you",
        NotificationType.Error,
        10000
    )
);
 
 
now everything is working well, except on the Work Order Spare Part Screen,  if the user assign a work order to him/her and they try to upload a photo then will get the following error:-
 
"Can not upload a photo for work order not assigned to you"
 
so seems the work order passed to the screen is still having the old data.. if i add a Refresh() (which i have commented them out in the above code) to the Assign button the problem will be solved
 
but why i need to issue a Refresh() which will affect the performance... and why the check is working well on one screen but not on the other screen?
  • FLMike Profile Picture
    FLMike 29,371 on 06 Oct 2024 at 19:32:58
    why i am not getting a refreshed item from sharePoint unless i do Refresh() operation
    Hi
     
    Yes, because the lookup is passed back so it ends up working, but not so on your initial screen.
     
    Can you share the Items properties of your Gallery
    And the Item Property of the form on screen 1?

    in these types of situations the best thing to do is write a literal action list in order 

    1. I loaded data into a gallery using XYZ for the Items
    2. bla bla.

    So that when you get to the point, where you say you go backwards, thats when we need to look at the varXXX you have and the code.

    The most underused arsenal you have is Monitor.
    1) start using trace statements in your code so you can track what actions happened and what ones didn't and to track what a variable holds in it

    So you wouldn't write

    Trace(variable)
    You would write
    Trace("VariableName=" & variable);

    So if that trace just says the first part in the literal string you can go oh.. i need to figure out why its wiped out.

    Also from screen to screen, the data is in a sense, refreshed for that one. You are saying, I believe
    if I go from screen 1 to 2, 2 shows it fine, but when I go from 2 to 1 it doesn't.

    Thats because going backwards at that point, you haven't refreshed the starting screen, but the other screens WERE refershed when you 
    loaded them for the first time.

    I do not believe in using Global Variables in this case. I use Context variables to pass them, that there is no way your data is missing.

    Example

    Screen 1 to screen 2
    Navigate(Screen2, Transition.WhateverOneYouWant, { _IDScreen1 = Gallery.Selected.ID (or wthaver) });

    Then in screen 1 itself when someone clicks on a Row in the Gallery

    UpdateContext(_ID = GalleryName.Selected.ID)

    And so on. Either way you need to prove the data is there, and thats what you are missing to do. We cannot see it at all, so its up to you to put the proper Tracing in. then using Monitor to find it.

    But what I said is what you will find, simply due to experience



  • johnjohnPter Profile Picture
    johnjohnPter 1,378 on 06 Oct 2024 at 17:13:22
    why i am not getting a refreshed item from sharePoint unless i do Refresh() operation
     
    Ok thanks , but after calling the workorder i am issuing a Lookup to get a new version of the work order, also the check will work well on one screen and fail on the other screen. so things is a bit confusing to me...
  • FLMike Profile Picture
    FLMike 29,371 on 06 Oct 2024 at 16:42:13
    why i am not getting a refreshed item from sharePoint unless i do Refresh() operation
    Hi
     
     
    The reason you have to refresh, is because you are doing the work OUTSIDE of the App. You cannot update the data somewhere else and have it instantly reflect it, no data is going to do that, that is cached locally.
     
    That's why you need to call refresh.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,238

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,290

Leaderboard

Featured topics

Loading complete