<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_resourcegroupitems(group_id, scenario_id, **kwargs):
 """ Get all the items in a group, in a scenario. If group_id is None, return all items across all groups in the scenario. """


    rgi_qry = db.DBSession.query(ResourceGroupItem).\
                filter(ResourceGroupItem.scenario_id==scenario_id)

    if group_id is not None:
        rgi_qry = rgi_qry.filter(ResourceGroupItem.group_id==group_id)

    rgi = rgi_qry.all()

    return rgi