load( local!staffingDetails, local!buttonValue, a!formLayout( label: "Rewrite Staffing ID", instructions: "", firstColumnContents: { a!sectionLayout( firstColumnContents: { a!integerField( label: "CSI Request ID", required: true(), validations: if( and( rule!APN_isEmpty( local!staffingDetails ), local!buttonValue = "fetch" ), "Invalid CSI ID", {} ), instructions: "Enter the request ID for rewriting the staffing ID", value: if( ri!requestID = 0, null, ri!requestID ), saveInto: ri!requestID ) }, secondColumnContents: { a!textField( label: "", readOnly: true() ) } ), a!buttonLayout( secondaryButtons: { a!buttonWidget( label: "Get Request Details", style: "PRIMARY", value: "fetch", saveInto: {local!buttonValue, a!save(local!staffingDetails, if( or(rule!APN_isEmpty(ri!requestID),ri!requestID<=0), null, a!queryEntity( entity: cons!CSI_STAFFING_ENTITY, query: a!query( filter: a!queryFilter( field: "hiringRequestId", operator: "=", value: ri!requestID ), pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 10 ) ) ).data )) } ) } ), if( and( rule!APN_isEmpty( local!staffingDetails ), local!buttonValue = "fetch" ), a!textField( label: "", value: "There is a problem retrieving information for this CSI request. Contact CSI Operator for further assistance.", readOnly: true() ), { a!sectionLayout( label: "Update Staffing Request", firstColumnContents: { a!gridLayout( label: "", instructions: "Below grid will display multiple records for a split request. Please update accordingly.", headerCells: { a!gridLayoutHeaderCell( label: "RequestID details" ), a!gridLayoutHeaderCell( label: "Standard ID" ), a!gridLayoutHeaderCell( label: "Staffing ID" ) }, rows: a!applyComponents( function: rule!CSI_renderCSIStaffingDetails( items: local!staffingDetails, index: _ ), array: if( or( isnull( local!staffingDetails ), count( local!staffingDetails ) < 1 ), {}, 1 + enumerate( count( local!staffingDetails ) ) ) ) ) } ), a!buttonLayout( secondaryButtons: { a!buttonWidget( label: "Submit Changes", style: "PRIMARY", value: "fetch", saveInto: local!buttonValue ) } ) } ) } ) )